[BS-26] UIView、pop和Core Animation区别
UIView、pop和Core Animation区别
一、UIView、pop和Core Animation的主要区别
1. Core Animation的动画只能添加到layer上(layer.position和view.frame类似)
2. pop的动画能添加到任何对象
3. pop的底层并非基于Core Animation, 是Facebook用OC和C++开发的基于CADisplayLink动画
4. Core Animation的动画仅仅是表象, 并不会真正修改对象的frame\size等值,通常用在不需要与用户交互的动画(如转场动画/下载进度动画)
5. pop和UIView实现的动画实时修改对象的属性, 真正地修改了对象的属性
二、pop动画应用举例
//弹簧动画 POPSpringAnimation *ani1 = [POPSpringAnimation animationWithPropertyNamed:kPOPViewAlpha]; [self.imgView pop_addAnimation:ani1 forKey:@"anim1"]; //可以通过[self.imgView pop_removeAnimationForKey:@"anim1"];移除该动画 ani1.fromValue = @1.0; ani1.toValue = @0.0; //基本的属性动画 POPBasicAnimation *anim2 = [POPBasicAnimation animationWithPropertyNamed:kPOPViewBackgroundColor]; //anim2.property = [POPAnimatableProperty propertyWithName:kPOPViewBackgroundColor]; [self.imgView pop_addAnimation:anim2 forKey:@"anim2"]; anim2.fromValue = [UIColor greenColor]; anim2.toValue = [UIColor yellowColor]; //衰减动画 //POPDecayAnimation *anim3 = [POPDecayAnimation animationWithPropertyNamed:kPOPViewFrame]; //自定义动画 //POPCustomAnimation *anim4 = [POPCustomAnimation animationWithBlock:<#^BOOL(id target, POPCustomAnimation *animation)block#>]; //延迟动画的方法 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { POPSpringAnimation *anim = [POPSpringAnimation animationWithPropertyNamed:kPOPViewCenter]; anim.springBounciness = 20; anim.springSpeed = 20; anim.fromValue = [NSValue valueWithCGPoint:CGPointMake(100, 100)]; anim.toValue = [NSValue valueWithCGPoint:CGPointMake(200, 200)]; [self.sloganView pop_addAnimation:anim forKey:nil]; POPSpringAnimation *anim = [POPSpringAnimation animationWithPropertyNamed:kPOPLayerPositionY]; anim.beginTime = CACurrentMediaTime() + 1.0; //延迟执行 anim.springBounciness = 20; anim.springSpeed = 20; anim.fromValue = @(self.sloganView.layer.position.y); anim.toValue = @(300); anim.completionBlock = ^(POPAnimation *anim, BOOL finished){ NSLog(@"-----动画结束"); }; [self.sloganView.layer pop_addAnimation:anim forKey:nil]; }
三、pop学习资料
1. https://github.com/facebook/pop
2. https://github.com/schneiderandre/popping
3. https://github.com/MartinRGB/LearnCube-iOS
4. POPAnimation给NSObject添加的分类方法
//NSObject添加的分类,任何对象都可以调用如下方法 @implementation NSObject (POP) - (void)pop_addAnimation:(POPAnimation *)anim forKey:(NSString *)key { [[POPAnimator sharedAnimator] addAnimation:anim forObject:self key:key]; } - (void)pop_removeAllAnimations { [[POPAnimator sharedAnimator] removeAllAnimationsForObject:self]; } - (void)pop_removeAnimationForKey:(NSString *)key { [[POPAnimator sharedAnimator] removeAnimationForObject:self key:key]; } - (NSArray *)pop_animationKeys { return [[POPAnimator sharedAnimator] animationKeysForObject:self]; } - (id)pop_animationForKey:(NSString *)key { return [[POPAnimator sharedAnimator] animationForObject:self key:key]; } @end
文章系作者原创,转载请注明出处:http://www.cnblogs.com/stevenwuzheng/p/5523252.html
如有错误,欢迎随时指正!
iOS开发者交流群:180080550