POP是一个在iOS与OS X上通用的极具扩展性的动画引擎。它在基本的静态动画的基础上增加的弹簧动画与衰减动画,使之能创造出更真实更具物理性的交互动画。POP的API可以快速的与现有的ObjC代码集成并可以作用于任意对象的任意属性;POP是个相当成熟且久经考验的框架,Facebook出品的令人惊叹的Paper应用中的所有动画和效果即出自POP。

 

 pop和Core Animation的区别

 1.Core Animation的动画只能添加到layer上

 2.pop的动画能添加到任何对象

 3.pop的底层并非基于Core Animation, 是基于CADisplayLink

 4.Core Animation的动画仅仅是表象, 并不会真正修改对象的frame\size等值

 5.pop的动画实时修改对象的属性, 真正地修改了对象的属性

 

示例代码一:pop弹簧动画    参数 kPOPViewCenter 改变UI控件的中心点

POPSpringAnimation *animation = [POPSpringAnimation animationWithPropertyNamed:kPOPViewCenter];

// 弹簧加强 0~20 默认 4

animation.springBounciness = 20;

//弹簧速度 0~20  默认 12

animation.springSpeed = 20;

animation.fromValue = [NSValue valueWithCGPoint:CGPointMake(50, 100)]; //从什么点位置开始

animation.toValue = [NSValue valueWithCGPoint:CGPointMake(200, 300)];//到什么点位置结束

// 为self.topImageView  添加动画

[self.topImageView pop_addAnimation:animation forKey:@"key"];

 

 示例代码二:通过改变图层的做弹簧动画      kPOPLayerPositionY 改变图层位置y值

POPSpringAnimation *animation = [POPSpringAnimation animationWithPropertyNamed:kPOPLayerPositionY];

// 如果用这个基类基本的动画没有弹簧效果 POPBasicAnimation  动画的执行节奏(一开始很慢, 后面很快) 但是弹簧加速和加强不能用

 //animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];

 //动画开始时间    CACurrentMediaTime()拿到当前时间  加上 2 秒后执行动画

 animation.beginTime = CACurrentMediaTime() + 2.0;

 // 从当前y位置开始 

 animation.fromValue = @(self.topImageView.layer.position.y);

 //到什么点位置结束

 animation.toValue = @(300);

//动画执行完后执行的Block,写一些动画结束后要执行的代码

 animation.completionBlock = ^(POPAnimation *anim, BOOL finished){

 NSLog(@"这里可以写动画结束后所要执行的代码");

 };

 //为 self.topImageView添加动画   参数:forKey可传 nil

 [self.topImageView pop_addAnimation:animation forKey:@"key"];

 

posted on 2017-06-30 00:20  chennet  阅读(234)  评论(0编辑  收藏  举报