• iOS开发UIMotionEffect运动视觉效果


    1、UIMotionEffect简介

      在iOS7.0推出了UIMotionEffect运动视觉效果,就是从屏幕偏移不同角度、看到的效果不同!

    NS_CLASS_AVAILABLE_IOS(7_0)
    @interface UIMotionEffect : NSObject <NSCopying, NSCoding>
    - (instancetype)init NS_DESIGNATED_INITIALIZER;
    - (nullable instancetype)initWithCoder:(NSCoder *)aDecoder NS_DESIGNATED_INITIALIZER;
    //观察者的角度偏移viewerOffset,获取运动视觉效果的各项属性和值
    - (nullable NSDictionary<NSString *, id> *)keyPathsAndRelativeValuesForViewerOffset:(UIOffset)viewerOffset;
    @end
    
    typedef NS_ENUM(NSInteger, UIInterpolatingMotionEffectType) {
        UIInterpolatingMotionEffectTypeTiltAlongHorizontalAxis,//X轴
        UIInterpolatingMotionEffectTypeTiltAlongVerticalAxis//Y轴
    };
    
    @interface UIInterpolatingMotionEffect : UIMotionEffect
    - (instancetype)initWithKeyPath:(NSString *)keyPath type:(UIInterpolatingMotionEffectType)type NS_DESIGNATED_INITIALIZER;//初始化
    - (nullable instancetype)initWithCoder:(NSCoder *)aDecoder NS_DESIGNATED_INITIALIZER;
    
    @property (readonly, nonatomic) NSString *keyPath;//获取角度偏移
    @property (readonly, nonatomic) UIInterpolatingMotionEffectType type;//获取类型
    @property (nullable, strong, nonatomic) id minimumRelativeValue;//最小角度偏移
    @property (nullable, strong, nonatomic) id maximumRelativeValue;//最大角度偏移
    @end
    
    @interface UIMotionEffectGroup : UIMotionEffect
    @property (nullable, copy, nonatomic) NSArray<__kindof UIMotionEffect *> *motionEffects;//添加水平和垂直效果添加到对应UI上
    @end

    2、简单使用

    - (void)addEffectWithOffset:(NSInteger)offset withView:(UIView *)view{
        UIInterpolatingMotionEffect *effectX = [[UIInterpolatingMotionEffect alloc] initWithKeyPath:@"center.x" type:UIInterpolatingMotionEffectTypeTiltAlongHorizontalAxis];
        effectX.minimumRelativeValue = @(-offset);
        effectX.maximumRelativeValue = @(offset);
        
        UIInterpolatingMotionEffect *effectY = [[UIInterpolatingMotionEffect alloc] initWithKeyPath:@"center.y" type:UIInterpolatingMotionEffectTypeTiltAlongVerticalAxis];
        effectY.minimumRelativeValue = @(-offset/2);
        effectY.maximumRelativeValue = @(offset/2);
        
    //    UIMotionEffectGroup *group = [[UIMotionEffectGroup alloc] init];
    //    group.motionEffects = @[effectX,effectY];
        view.motionEffects = @[effectX,effectY];
    }
  • 相关阅读:
    Linux内核分析— —操作系统是如何工作的(20135213林涵锦)
    【BARTS计划】【Share_Week1】社交产品思考
    【BARTS计划】【Tips_Week1】20190331更新
    【BARTS计划】【Review_Week1】Google Docs 成为青少年们喜爱的聊天 app
    【学习博客】Python学习初体验
    《构建之法》读书笔记5
    《构建之法》8&16
    《构建之法》读书笔记4
    《构建之法》读书笔记3
    《构建之法》读书笔记2
  • 原文地址:https://www.cnblogs.com/xianfeng-zhang/p/8926538.html
Copyright © 2020-2023  润新知