PGSSoft / ParallaxView

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

Only allow parallax vertically? #17

Closed taschmidt closed 5 years ago

taschmidt commented 5 years ago

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?

taschmidt commented 5 years ago

Nvm, looks like setting parallaxMotionEffect.viewingAngleY = 0 does the trick.

taschmidt commented 5 years ago

Actually, this didn't quite get me all the way to what I wanted. There's no more parallax horizontally, but I can still wiggle it side to side. Is there any way to remove that?

taschmidt commented 5 years ago

Ok, just answering my own question again. I'll leave this for posterity. It finally occurred to me that what I wanted in this instance wasn't actually even a parallax, so trying to make a parallax view do it didn't make much sense.

I ended up just adding my own custom motion effects like so:

if context.nextFocusedView == self {
    let effect = UIInterpolatingMotionEffect(keyPath: "center.y", type: .tiltAlongVerticalAxis)
    effect.minimumRelativeValue = -8
    effect.maximumRelativeValue = 8
    self.addMotionEffect(effect)
} else {
    self.motionEffects.removeAll()
}