Using Motion Effects

文档说只有动画的属性可以用这个类
直接上高手的代码吧
// Do any additional setup after loading the view, typically from a nib.

//Min and max values -- The higher these #s are, the more pronouced the effect
CGFloat leftRightMin = -55.0f;
CGFloat leftRightMax = 55.0f;

CGFloat upDownMin = -35.0f;
CGFloat upDownMax = 35.0f;

//Motion Effect
UIInterpolatingMotionEffect * leftRight = [[UIInterpolatingMotionEffect alloc]initWithKeyPath:@"center.x" type:UIInterpolatingMotionEffectTypeTiltAlongHorizontalAxis];

leftRight.minimumRelativeValue = @(leftRightMin);
leftRight.maximumRelativeValue = @(leftRightMax);


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

upDown.minimumRelativeValue = @(upDownMin);
upDown.maximumRelativeValue = @(upDownMax);

//Create a motion effect group
UIMotionEffectGroup * meGroup = [[UIMotionEffectGroup alloc]init];
meGroup.motionEffects = @[leftRight, upDown];

//Add the motion effect group to our imageView
[myImageView addMotionEffect:meGroup];
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • ViewsBecause view objects are the main way your applicati...
    梁光飞阅读 681评论 0 0
  • PLEASE READ THE FOLLOWING APPLE DEVELOPER PROGRAM LICENSE...
    念念不忘的阅读 13,568评论 5 6
  • 在iOS实际开发中常用的动画无非是以下四种:UIView动画,核心动画,帧动画,自定义转场动画。 1.UIView...
    请叫我周小帅阅读 3,220评论 1 23
  • 我是不是变懒了,两周才更新一遍周几。是的。拍婚纱照啦~姑娘仙儿得哟,确实挺好的,只不过工厂模式批量生产,木办法,这...
    筱筱殿下阅读 169评论 0 0
  • 春雨急急扰清梦,滴滴答答到天明。 古人有箴:诗词文章多断残者,寿似不永。 按着这个标准,我绝对寿数难长……
    王宝宏的微博阅读 418评论 4 1