Giter Site home page Giter Site logo

pgssoft / parallaxview Goto Github PK

View Code? Open in Web Editor NEW
476.0 13.0 49.0 4.17 MB

tvOS controls and extensions that add parallax effect to your application.

Home Page: https://pgssoft.github.io/ParallaxView/

License: MIT License

Swift 97.24% Ruby 1.62% Objective-C 1.14%

parallaxview's Introduction

PGS Software

ParallaxView

Swift 5.0 CocoaPods Compatible Carthage Compatible SPM Compatible Platform License

Summary

Easy to use UIView, UICollectionViewCell with parallax effect and extensions to add this effect to any UIView. Rotate view using Apple TV remote. Works confusingly similar to tiles in the home screen of the Apple TV.

ParallaxView ParallaxView

ParallaxView

Open your storyboard or xib and drag and drop UIView control. Change custom class to ParallaxView in Identity inspector. You can also create control from code.

ParallaxCollectionViewCell

In Interface builder change collection view cell class to ParallaxCollectionViewCell or do it from code.

You can also create subclass of ParallaxCollectionViewCell insted of UICollectionViewCell and use it as normal collection view cell.

Extension

If ParallaxView and ParallaxCollectionViewCell don't fit to your needs you can use extension that can be used with any UIView. In many cases it can look like in this example:

override func didUpdateFocus(in context: UIFocusUpdateContext, with coordinator: UIFocusAnimationCoordinator) {
	coordinator.addCoordinatedAnimations({
		if context.nextFocusedView === yourCustomView {
			yourCustomView.addParallaxMotionEffects()
		}
		if context.previouslyFocusedView === yourCustomView {
			yourCustomView.removeParallaxMotionEffects()
		}
	}, completion: nil)
}

It is important to add and remove parallax effect inside the animation block to avoid the glitches. ParallaxView and ParallaxCollectionViewCell internally use the same methods. For more details look into example.

Customisation

The component is documented in code, also look into example for more details.

Documentation

Properties

ParallaxView and ParallaxCollectionViewCell have the same properties for customisation.

  • parallaxEffectOptions - using this property you can customize parallax effect.

    • parallaxMotionEffect - configure parallax effect (pan, angles, etc.)
    • subviewsParallaxMode - enum that allow you to configure parallax effect for subviews of the ParallaxView
    • shadowPanDeviation - maximal value of points that shadow of the ParallaxView will be moved during parallax effect
    • glowAlpha - configure alpha of the glow effect (if is equal to 0.0 then the glow effect will be not added)
    • parallaxSubviewsContainer - custom container view that will be usead to apply subviews parallax effect. By default it will be parallaxable view by itself.
    • glowContainerView - view that will be used as the container for the glow effect. You don't have to configure this because for ParallaxView it will be automatically created a subview for this purpose, while for ParallaxCollectionViewCell it will be used contentView of the cell. Also by default it is nil when you use extension (self will be used as the glow container but only if glowAlpha is bigger than 0.0). But if you want to, you can define custom view - look into example project for more details.
    • glowImageView - image view that will be used as the glow effect. ParallaxView framework provides default image that will be set.
  • glowPosition - (.top default) - allows to customize position of the glow effect related to the glowImageContainer. You can provide custom setup by creating GlowPosition instance.

  • parallaxViewActions - use properties of this property to change default behaviours of the parallax view. Internally both ParallaxView and ParallaxCollectionViewCell calls callbacks.

    • setupUnfocusedState - closure will be called in animation block when view should change its appearance to the focused state
    • setupFocusedState - closure will be called in animation block when view should change its appearance to the unfocused state
    • beforeBecomeFocusedAnimation - closure will be called before the animation to the focused change start
    • beforeResignFocusAnimation - closure will be called before the animation to the unfocused change start
    • becomeFocused - closure will be called when didFocusChange happened. In most cases default implementation should work
    • resignFocus - closure will be called when didFocusChange happened. In most cases default implementation should work.
    • animatePressIn - default implementation of the press begin animation
    • animatePressOut - default implementation of the press ended animation
  • cornerRadius - use this value insted of self.view.layer.cornerRadius. This will automatically correct radius for glow effect view if it is necessary

Requirements

Swift 5.0, tvOS 9.0

Installation

Add line to Podfile

# ...
target 'MyApp' do
  # your other pod
  # ...
  pod 'ParallaxView'
end
# ...

Add a line to Cartfile:

github "PGSSoft/ParallaxView"

Xcode 12 (Swift 5.3) required!

In Xcode:

Select File > Swift Packages > Add Package Dependency. Enter https://github.com/PGSSoft/ParallaxView

If you would like to check more details please visit the Apple's documentation

  • Manual

You can download the latest files from our Releases page. After doing so, drag ParallaxView.xcodeproj into your project in Xcode, and for your project target on General tab in Embedded Binaries section add ParallaxView.framework. Example project is configured the same way, so you have the crib sheet.

Usage

import ParallaxView

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/PGSSoft/ParallaxView.

License

The project is available as open source under the terms of the MIT License.

About

The project maintained by software development agency PGS Software. See our other open-source projects or contact us to develop your product.

Follow us

Twitter URL
Twitter Follow

parallaxview's People

Contributors

dcordero avatar nonameplum avatar stefanomondino avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

parallaxview's Issues

Parallax effect

Thank you very much for this library.
I am using it inside my Apple TV application and I noticed that the first cell in my UICollectionView has a weird effect when it was focused. You can see how it looked in the image attached. Would you please help me fix it.

Screen Shot 2021-05-28 at 3 40 15 PM

Issue in tvOS 15.0

We are working on an OTT app that has many carousels in a home screen created with a collection view inside another collection view (one for horizontal scrolling and another for vertical scrolling). The top-level collection view is part of a child view controller, of a root view controller which has a side menu as another child. This menu view controller has focusable items in it. Till tvOS 14 we were able to navigate from the carousels to the side menu, but since tvOS 15 when we subclassing Parallax Cell the focus is not updating to the side menu. This is happening for only collection view cells with nib in it.

If you need further information I am happy to share it. Please let me know
Thanks

Weird shaking-effect when focusing ParallaxViews

Hi there,

im getting weird effects on the ParallaxViews on the element that is getting focused in any direction. When focusing element, it is shaking to left and right for a split second.
Doesnt happen with the CollectionViewCells.

Same on the example on "Any View" if you go from the label to the orange element.

Retain cycle in ParallaxView?

Hi, I'm experiencing what appears to be memory leaks using ParallaxView.

The more I use the app, the more unreleased closures are kept in memory.

A2953589-ED29-4C0B-B454-05364C5C3489

In my cell, I have a ParallaxView and I use a similar code as the one given in README of the project.

Relevant excerpt of the code:

@IBOutlet weak var posterView: ParallaxView!

...

override func didUpdateFocus(in context: UIFocusUpdateContext, with coordinator: UIFocusAnimationCoordinator) {
      super.didUpdateFocus(in: context, with: coordinator)
      coordinator.addCoordinatedAnimations { [weak self] in
          guard let self = self else { return }
          if context.nextFocusedView == self {
              self.posterView.addParallaxMotionEffects()
              UIView.animate(withDuration: 0.15, delay: 0, options: .curveEaseOut) {
                  self.posterView.transform = CGAffineTransform(scaleX: 1.1, y: 1.1)
              }
          }
          if context.previouslyFocusedView == self {
              self.posterView.removeParallaxMotionEffects()
              UIView.animate(withDuration: 0.3, delay: 0, options: .curveLinear) {
                  self.posterView.transform = CGAffineTransform(scaleX: 1, y: 1)
              }
          }
      }
  }

Any idea what might be the issue?
Thank you in advance!

subviewsParallaxMode not working properly in UICollectionViewCell

I would like to achieve some subview parallax effect in my custom collection view cells (created in a xib file).
I have a UIImageView covering all the cell's space, with some text on top.
The cell is a ParallaxCollectionViewCell subclass, and I'd like to use .basedOnTag mode.
This kind of behavior is currently not possible

in
public func addParallaxMotionEffects(with options: inout ParallaxEffectOptions)
the interpolation causing the parallax effect is applied to all the (first level) subviews, but a collection view cell only has one subview (the content view). All my subviews are inside the system-defined content view, so the intended effect will never be able to work properly.
I'd like to change the subviews property used at line 87 (and 120) of UIView+ParallaxEffect
subviews .filter { $0 !== options.glowContainerView } .enumerated() .forEach { (index: Int, subview: UIView) in

to something like this
let subviews = (self as? ParallaxCollectionViewCell)?.contentView.subviews ?? self.subviews

Does this make sense?

Only allow parallax vertically?

By default, your view allows the parallax effect in all directions. Our designer brought up the fact that, in a vertically scrolling list, Apple uses the parallax effect only when moving up and down as a hint to the user as to the scroll direction. Is there an easy way to achieve this?

Lock swipe directions

Hi everybody.
Thank you for this library, I really like it.
Now I want to create buttons to play, buy and rent movie (the same way as it is in the movies iTunes application). As I can see for such buttons user can swipe to the left and to the right only. But now I see that ParallaxView handles all swipes and I don't know how to lock some swipe directions. Could you please help me? Thank you in advance.

button support

ParallaxViewActions is marked internal so I can't create custom UIButton or any other control for that instance

Setting a glowContainerView removes UICollectionViewCell#contentView from hierarchy

Hello and first of all thanks for a great library!

With version > 3.0.0 or more specifically since commit acaa9b6 I see an issue with setting a custom glowContainerView on the ParallaxEffectOptions property of my UICollectionViewCell. No matter how I set the glowContainerView property it results in the cell's contentView being removed from its superview and the cell has no visible content in the UICollectionView.

My cell inherits from ParallaxCollectionViewCell and in awakeFromNib() or setupParallax() I would like to customize the ParallaxEffectOptions by using the options property and set a different glowContainerView. The glowContainerView property however is at this point already initialized with the cell's contentView (happens in ParallaxCollectionViewCell#commonInit). Setting a different glowContainerView subsequently leads to the contentView being removed from its superview by a property observer. As commonInit is called from the initializer I couldn't find a way to set my own glowContainerView before the contentView is set as default.

My first guess for a fix would be to remove the property observer on glowContainerView so that it doesn't change the view hierarchy. I am not sure of possible side effects however.

Kind regards and all the best,
Markus

ParallaxView v2.0.8

Hello Łukasz,

could it be possible to have a new release of ParallaxView with the changes introduced in this PR?
#5

Those changes should be 100% backward compatible and it would allow us to start adapting our App to tvOS 11 more easily.

Thanks a lot btw for sharing this great project 🎩

glow image customizability

while developing in simulator, the glow seems fine. when viewed in a high res tv, the glow shows aliasing.

so I was thinking for the original glow image to be rendered using CoreGraphics or
for a custom glow image to be set.

Suggestion: canbecomefocused

working with collectionView, sometimes you want the collectionViewDelegate to
decide whether to allow focus or not via
func collectionView(_ collectionView: UICollectionView, canFocusItemAt indexPath: IndexPath) -> Bool

after some time of investigation, I discovered that when a collectionviewcell overrides
canBecomeFocused, the collectionViewDelegate function
func collectionView(_ collectionView: UICollectionView, canFocusItemAt indexPath: IndexPath) -> Bool
doesn't get called.

to solve this issue, I just commented the code
in ParallaxCollectionViewCell,

//open override var canBecomeFocused : Bool {
//        return true
//}

Visual Glitch

Hi!

I've ran into an issue where I have a UIStackView with two UIButton inside (which are working fine) and a separate UIButton on my screen but if I focus on the single button outside the UIStackView starts to glitch out while I'm moving around the effect on the button.

Any ideas?

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.