PGSSoft / ParallaxView

tvOS controls and extensions that add parallax effect to your application.
https://pgssoft.github.io/ParallaxView/
MIT License
481 stars 50 forks source link

subviewsParallaxMode not working properly in UICollectionViewCell #3

Closed stefanomondino closed 7 years ago

stefanomondino commented 7 years ago

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?

stefanomondino commented 7 years ago

4 here's an implementation with customizable container

nonameplum commented 7 years ago

@stefanomondino Thanks for you contribution and pr. Instead of using inheritance I would like to stick with composition using existing ParallaxEffectOptions struct that is used for this purpose. Please take a look at the changes that I have made and please let me know if that will work you.

https://github.com/PGSSoft/ParallaxView/compare/pr/4

stefanomondino commented 7 years ago

Thanks, I total agree with your solution. I'll try it out in few days but seems good to me. Thank you very much:)

stefanomondino commented 7 years ago

works like a charm! can you please merge it and release it?

nonameplum commented 7 years ago

Feature added with https://github.com/PGSSoft/ParallaxView/releases/tag/2.0.7