iOS 7 parallax effect in my view controller

前端 未结 9 2069
终归单人心
终归单人心 2020-11-30 16:27

I\'m developing an app for iOS 7 in Objective-C. I\'ve got a screen in my app with a few buttons and a pretty background image. (It\'s a simple xib with UIButtons

9条回答
  •  青春惊慌失措
    2020-11-30 16:34

    const static CGFloat kCustomIOS7MotionEffectExtent = 10.0; 
    
    - (void)applyMotionEffects:(UIView *YOUR_VIEW) {
         if (NSClassFromString(@"UIInterpolatingMotionEffect")) {
             UIInterpolatingMotionEffect *horizontalEffect = [[UIInterpolatingMotionEffect alloc] initWithKeyPath:@"center.x"
                                                                                                            type:UIInterpolatingMotionEffectTypeTiltAlongHorizontalAxis];
             horizontalEffect.minimumRelativeValue = @(-kCustomIOS7MotionEffectExtent);
             horizontalEffect.maximumRelativeValue = @( kCustomIOS7MotionEffectExtent);
             UIInterpolatingMotionEffect *verticalEffect = [[UIInterpolatingMotionEffect alloc] initWithKeyPath:@"center.y"
                                                                                                          type:UIInterpolatingMotionEffectTypeTiltAlongVerticalAxis];
             verticalEffect.minimumRelativeValue = @(-kCustomIOS7MotionEffectExtent);
             verticalEffect.maximumRelativeValue = @( kCustomIOS7MotionEffectExtent);
             UIMotionEffectGroup *motionEffectGroup = [[UIMotionEffectGroup alloc] init];
             motionEffectGroup.motionEffects = @[horizontalEffect, verticalEffect]; 
             [YOUR_VIEW addMotionEffect:motionEffectGroup];
         }
    }
    

提交回复
热议问题