zoukankan      html  css  js  c++  java
  • Facebook 开源动画库 pop

    一:pop的基本构成:

    • POPPropertyAnimation 属性动画

    • POPSpringAnimation 弹簧效果动画

    • POPBasicAnimation 基于动画

    • POPDecayAnimation 延迟衰减动画

    • POPCustomAnimation 自定义动画

    二:其中属性动画的类型:

    #pragma mark - Static
    
    NSString * const kPOPLayerBackgroundColor = @"backgroundColor";
    NSString * const kPOPLayerBounds = @"bounds";
    NSString * const kPOPLayerOpacity = @"opacity";
    NSString * const kPOPLayerPosition = @"position";
    NSString * const kPOPLayerPositionX = @"positionX";
    NSString * const kPOPLayerPositionY = @"positionY";
    NSString * const kPOPLayerRotation = @"rotation";
    NSString * const kPOPLayerRotationX = @"rotationX";
    NSString * const kPOPLayerRotationY = @"rotationY";
    NSString * const kPOPLayerScaleX = @"scaleX";
    NSString * const kPOPLayerScaleXY = @"scaleXY";
    NSString * const kPOPLayerScaleY = @"scaleY";
    NSString * const kPOPLayerSize = @"size";
    NSString * const kPOPLayerSubscaleXY = @"subscaleXY";
    NSString * const kPOPLayerSubtranslationX = @"subtranslationX";
    NSString * const kPOPLayerSubtranslationXY = @"subtranslationXY";
    NSString * const kPOPLayerSubtranslationY = @"subtranslationY";
    NSString * const kPOPLayerSubtranslationZ = @"subtranslationZ";
    NSString * const kPOPLayerTranslationX = @"translationX";
    NSString * const kPOPLayerTranslationXY = @"translationXY";
    NSString * const kPOPLayerTranslationY = @"translationY";
    NSString * const kPOPLayerTranslationZ = @"translationZ";
    NSString * const kPOPLayerZPosition = @"zPosition";
    
    NSString * const kPOPViewAlpha = @"view.alpha";
    NSString * const kPOPViewBackgroundColor = @"view.backgroundColor";
    NSString * const kPOPViewBounds = kPOPLayerBounds;
    NSString * const kPOPViewCenter = @"view.center";
    NSString * const kPOPViewFrame = @"view.frame";
    NSString * const kPOPViewScaleX = @"view.scaleX";
    NSString * const kPOPViewScaleXY = @"view.scaleXY";
    NSString * const kPOPViewScaleY = @"view.scaleY";
    NSString * const kPOPViewSize = kPOPLayerSize;
    
    NSString * const kPOPTableViewContentOffset = @"tableView.contentOffset";
    NSString * const kPOPTableViewContentSize = @"tableView.contentSize";

    使用:

        POPSpringAnimation *springAnimation = [POPSpringAnimation animationWithPropertyNamed:kPOPLayerSize];

    三:

    示例1:演示图片放大效果动画

    @interface PPPictureConstraintViewController ()
    @property (weak, nonatomic) IBOutlet NSLayoutConstraint *widthConstraint;
    @property (weak, nonatomic) IBOutlet NSLayoutConstraint *heightConstraint;
    
    @end
    
    @implementation PPPictureConstraintViewController
    
    - (void)performFullScreenAnimation
    {
        //先去除所有的动画
        [self.widthConstraint pop_removeAllAnimations];
        [self.heightConstraint pop_removeAllAnimations];
        
        //创建弹簧动画1
        POPSpringAnimation *heightAnimation = [POPSpringAnimation animationWithPropertyNamed:kPOPLayoutConstraintConstant];
        heightAnimation.springBounciness = 8;
        
        //创建弹簧动画2
        POPSpringAnimation *animation = [POPSpringAnimation animationWithPropertyNamed:kPOPLayoutConstraintConstant];
        animation.springBounciness = 8;
        
        if (!_isInFullscreen)
        {
            animation.toValue = @(320.);
            heightAnimation.toValue = @(208.);
        }
        else
        {
            animation.toValue = @(182.);
            heightAnimation.toValue = @(118.);
        }
        
        //加载动画
        [self.heightConstraint pop_addAnimation:heightAnimation forKey:@"fullscreen"];
        [self.widthConstraint pop_addAnimation:animation forKey:@"fullscreen"];
        
    }
    
    @end

    示例2:创建一个旋转及点击放大 + 号 动画

    - (IBAction)bigBounceButtonWasPressed:(UIButton *)sender
    {
        _buttonToggle = !_buttonToggle;
        
        CALayer *layer = sender.layer;
        
        [layer pop_removeAllAnimations];
        POPSpringAnimation  *anim = [POPSpringAnimation animationWithPropertyNamed:kPOPLayerSize];
        POPSpringAnimation *rotation = [POPSpringAnimation animationWithPropertyNamed:kPOPLayerRotation];
    
        if (_buttonToggle)
        {
            anim.toValue = [NSValue valueWithCGSize:CGSizeMake(44, 44)];
            rotation.toValue = @(M_PI_4);
            sender.tintColor = [UIColor colorWithRed:0.0 green:122.0/255.0 blue:1.0 alpha:1.0];
        }
        else
        {
            anim.toValue = [NSValue valueWithCGSize:CGSizeMake(34, 34)];
            rotation.toValue = @(0);
            sender.tintColor = [UIColor redColor];
        }
        
        anim.springBounciness = 20;
        anim.springSpeed = 16;
        
        anim.completionBlock = ^(POPAnimation *anim, BOOL finished) {
            NSLog(@"Animation has completed.");
        };
        [layer pop_addAnimation:anim forKey:@"size"];
        [layer pop_addAnimation:rotation forKey:@"rotation"];
    }

    四:参考:

  • 相关阅读:
    043 抖音短视频爬取实战
    048 Python里面yield的实现原理
    047 Python面试知识点小结
    001 Glang实现简单分布式缓存
    046 算法的时间复杂度和空间复杂度计算
    042 使用Python远程监视多个服务器和数据库的状态,python,监控,同步
    041基于python实现jenkins自动发布代码平台
    045 chrome浏览器前端调试技巧
    STL学习
    Asio与Boost.Asio
  • 原文地址:https://www.cnblogs.com/cocoajin/p/3708593.html
Copyright © 2011-2022 走看看