zoukankan      html  css  js  c++  java
  • [BS-26] UIView、pop和Core Animation区别

    UIView、pop和Core Animation区别

     

     一、UIView、popCore Animation的主要区别

     1. Core Animation的动画只能添加到layer上(layer.position和view.frame类似)

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

     3. pop的底层并非基于Core Animation, 是Facebook用OC和C++开发的基于CADisplayLink动画

     4. Core Animation的动画仅仅是表象, 并不会真正修改对象的framesize等值,通常用在不需要与用户交互的动画(如转场动画/下载进度动画)

     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

    如有错误,欢迎随时指正!

     

  • 相关阅读:
    机器学习笔记(二)---- 线性回归
    机器学习笔记(一)----基本概念
    ZZ:SDNLAB技术分享(一):ODL的SFC入门和Demo
    zz:NETCONF协议详解
    技术谈 | SDN 和 NFV 之间的爱与恨
    华为云内容审核—性能更加狂野,价格更加腼腆
    【并发技术01】传统线程技术中创建线程的两种方式
    【开发者portal在线开发插件系列五】命令的响应,即命令结果的上报(mid的使用)
    【并发技术16】线程同步工具Exchanger的使用
    什么是API文档?--斯科特·马文
  • 原文地址:https://www.cnblogs.com/stevenwuzheng/p/5523252.html
Copyright © 2011-2022 走看看