I'm trying to get a parallax effect similar to the home screen background. I've seen numerous examples of this working with a UIInterpolatingMotionEffect but I cannot get it to work on my iOS 14 devices (I've confirmed that the reduce motion setting is NOT enabled and the home screen background is moving like normal, so I know it works on my device).
I've tried variations of this code, adding it to a view / button / label and nothing happens... any ideas? Thank you!
I've tried variations of this code, adding it to a view / button / label and nothing happens... any ideas? Thank you!
Code Block let horizontal = UIInterpolatingMotionEffect(keyPath: "center.x", type: .tiltAlongHorizontalAxis) horizontal.minimumRelativeValue = -50 horizontal.maximumRelativeValue = 50 let vertical = UIInterpolatingMotionEffect(keyPath: "center.x", type: .tiltAlongVerticalAxis) vertical.minimumRelativeValue = -50 vertical.maximumRelativeValue = 50 let group = UIMotionEffectGroup() group.motionEffects = [horizontal, vertical] label.addMotionEffect(group)
I don't know, is it a bug, or some new mega-features:)
If you call addMotionEffect in init or other method before your view really appeared at the screen - it doesn't work. But if you do it when your view is at the screen - its OK!!!
Here's my working solution:
override func didMoveToWindow() {
super.didMoveToWindow()
guard window != nil else {
pictureView.removeMotionEffect(pictureParralaxEffect)
return
}
pictureView.addMotionEffect(pictureParralaxEffect)
}
(Sorry for my awful English))))
If you call addMotionEffect in init or other method before your view really appeared at the screen - it doesn't work. But if you do it when your view is at the screen - its OK!!!
Here's my working solution:
override func didMoveToWindow() {
super.didMoveToWindow()
guard window != nil else {
pictureView.removeMotionEffect(pictureParralaxEffect)
return
}
pictureView.addMotionEffect(pictureParralaxEffect)
}
(Sorry for my awful English))))