15.11.05笔记

UIInterpolatingMotionEffect  

苹果文档的解释是:
A UIInterpolatingMotionEffect object maps the horizontal or vertical tilt of a device to values that you specify so that UIKit can apply those values to your views. You use this class to determine the amount of tilt along a single axis to apply to a view。

使用UIInterpolatingMotionEffect可以使页面随着设备在空间的移动而发生微移。


关于UIInterpolatingMotionEffect的方法参数如下:
NS_CLASS_AVAILABLE_IOS(7_0) 

@interface UIInterpolatingMotionEffect : UIMotionEffect
- (instancetype)initWithKeyPath:( NSString *)keyPath type:UIInterpolatingMotionEffectType)type; // designated initializer
@property (readonly, nonatomic) NSString *keyPath;
@property (readonly, nonatomic) UIInterpolatingMotionEffectType type;//动画方向-用水平和竖直之分
@property (retain, nonatomic) id minimumRelativeValue;//最小偏移
@property (retain, nonatomic) id maximumRelativeValue;//最大偏移
@end
其中keyPath的意思是:”This property must correspond to an animatable property of the view to which the motion effect is attached. For example, to update the center property of the view, specify the string “center”. “.
同时为了适应这种变化,UIView上增加了关于MotionEffects的几个方法如下:
@interface UIView (UIViewMotionEffects)
- (void)addMotionEffect:(UIMotionEffect *)effect NS_AVAILABLE_IOS(7_0);
- (void)removeMotionEffect:(UIMotionEffect *)effect NS_AVAILABLE_IOS(7_0);
@property (copy, nonatomic) NSArray *motionEffects NS_AVAILABLE_IOS(7_0);
@end


 // Motion effects

        UIInterpolatingMotionEffect *horizontalMotionEffect = [[UIInterpolatingMotionEffect alloc] initWithKeyPath:@"center.x" type:UIInterpolatingMotionEffectTypeTiltAlongHorizontalAxis];

        horizontalMotionEffect.minimumRelativeValue = @(-10);

        horizontalMotionEffect.maximumRelativeValue = @(10);

        

        UIInterpolatingMotionEffect *verticalMotionEffect = [[UIInterpolatingMotionEffect alloc] initWithKeyPath:@"center.y" type:UIInterpolatingMotionEffectTypeTiltAlongVerticalAxis];

        verticalMotionEffect.minimumRelativeValue = @(-10);

        verticalMotionEffect.maximumRelativeValue = @(10);

        

        UIMotionEffectGroup *group = [UIMotionEffectGroup new];

        group.motionEffects = @[horizontalMotionEffect, verticalMotionEffect];

        [self.alertView addMotionEffect:group];

UIBlurEffect 毛玻璃(blur)效果

UIVisualEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleExtraLight];

            UIVisualEffectView *visualEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];

            visualEffectView.frame = frame;

            [self.view addSubview:visualEffectView];


你可能感兴趣的:(15.11.05笔记)