控件运动效果

IOS

运动效果就是利用加速度传感器,当你在左右摇手机的时候控件也在跟着左右动。(好像除了装逼没什么卵用啊~)

比如将一个_button的添加运动效果:

//OC
 UIInterpolatingMotionEffect *motionEffect;
    motionEffect = [[UIInterpolatingMotionEffect alloc] initWithKeyPath:@"center.x" type:UIInterpolatingMotionEffectTypeTiltAlongHorizontalAxis];
    motionEffect.minimumRelativeValue = @(-25);  //觉得不明显可以把参数改大一点
    motionEffect.maximumRelativeValue = @(25);
    [_button addMotionEffect:motionEffect];
    
    motionEffect = [[UIInterpolatingMotionEffect alloc] initWithKeyPath:@"center.y" type:UIInterpolatingMotionEffectTypeTiltAlongVerticalAxis];
    motionEffect.minimumRelativeValue = @(-25);
    motionEffect.maximumRelativeValue = @(25);
    [_button addMotionEffect:motionEffect];

一定要用真机才看得到效果