根据手机转动的角度,显示图片的不同部分,视图上产生视差晃动的效果,仅能在真机中测试。
depth:一个偏移量
#pragma mark -Auxiliares
- (void)registerEffectForView:(UIView *)aView depth:(CGFloat)depth;
{
UIInterpolatingMotionEffect *effectX;
UIInterpolatingMotionEffect *effectY;
effectX = [[UIInterpolatingMotionEffect alloc] initWithKeyPath:@"center.x"
type:UIInterpolatingMotionEffectTypeTiltAlongHorizontalAxis];
effectY = [[UIInterpolatingMotionEffect alloc] initWithKeyPath:@"center.y"
type:UIInterpolatingMotionEffectTypeTiltAlongVerticalAxis];
effectX.maximumRelativeValue = @(depth);
effectX.minimumRelativeValue = @(-depth);
effectY.maximumRelativeValue = @(depth);
effectY.minimumRelativeValue = @(-depth);
[aView addMotionEffect:effectX];
[aView addMotionEffect:effectY];
}