Using UICollectionView , I ran into the same problem. After clicking on the new controller, and then back to the UICollectionView , some of my UIInterpolatingMotionEffect cells stopped working, but were still specified in the motionEffects .
Solution: I called to configure the motion effects in -layoutSubviews , and whenever I set up the cell, I called -setNeedsLayout to ensure that -layoutSubviews was called.
In addition, every time I adjust the motion effects, I would delete the previous motion effects. That was the key.
Here is the method I called in -layoutSubviews :
- (void)applyInterpolatingMotionEffectToView:(UIView *)view withParallaxLimit:(CGFloat)limit { NSArray *effects = view.motionEffects; for (UIMotionEffect *motionEffect in effects) { [view removeMotionEffect:motionEffect]; } UIInterpolatingMotionEffect *effectX = [[UIInterpolatingMotionEffect alloc] initWithKeyPath: @"center.x" type: UIInterpolatingMotionEffectTypeTiltAlongHorizontalAxis]; effectX.minimumRelativeValue = @(-limit); effectX.maximumRelativeValue = @(limit); UIInterpolatingMotionEffect *effectY = [[UIInterpolatingMotionEffect alloc] initWithKeyPath: @"center.y" type: UIInterpolatingMotionEffectTypeTiltAlongVerticalAxis]; effectY.minimumRelativeValue = @(-limit); effectY.maximumRelativeValue = @(limit); [view addMotionEffect: effectX]; [view addMotionEffect: effectY]; }
Hope this helps! Also works on iOS 9.
source share