zoukankan      html  css  js  c++  java
  • iOS动画——弹窗动画(pop动画)

        用pop动画简单实现弹窗的缩放渐变,感觉这个动画常用,就写一下博客

       pop动画是Facebook推出的动画引擎,请自行到GitHub上搜索下载拖拽导入xcode项目中。

      更多pop动画使用和原理可网上搜索学习

      本处只简单介绍代码开发使用,紧以弹窗效果为思路。

        




      1. 控制器导入头文件 #import "POP.h"


      2.创建弹窗透明黑色背景

    1. - (void)createBlackView {  
    2.       
    3.     self.blackView                 = [[UIView alloc] initWithFrame:self.contentView.bounds];  
    4.     self.blackView.backgroundColor = [UIColor blackColor];  
    5.     self.blackView.alpha           = 0;  
    6.     [self addSubview:self.blackView];  
    7.       
    8.     [UIView animateWithDuration:0.3f animations:^{  
    9.           
    10.         self.blackView.alpha = 0.25f;  
    11.     }];  
    12. }  


    3.创建白色上面的白色view,并加上所需的控件,给白色的messageView做pop动画效果,

      代码如下


    1. // 执行动画 改变透明度  
    2.  POPBasicAnimation  *alpha = [POPBasicAnimation animationWithPropertyNamed:kPOPViewAlpha];  
    3.  alpha.toValue             = @(1.f);  
    4.  alpha.duration            = 0.3f;  
    5.  [self.messageView pop_addAnimation:alpha forKey:nil];  
    6.  // 缩放回弹  
    7.  POPSpringAnimation *scale = [POPSpringAnimation animationWithPropertyNamed:kPOPLayerScaleXY];  
    8.  scale.fromValue           = [NSValue valueWithCGSize:CGSizeMake(1.75f, 1.75f)];  
    9.  scale.toValue             = [NSValue valueWithCGSize:CGSizeMake(1.f, 1.f)];  
    10.  scale.dynamicsTension     = 1000;  
    11.  scale.dynamicsMass        = 1.3;  
    12.  scale.dynamicsFriction    = 10.3;  
    13.  scale.springSpeed         = 20;  
    14.  scale.springBounciness    = 15.64;  
    15.  scale.delegate            = self;  
    16.  [self.messageView.layer pop_addAnimation:scale forKey:nil];  


    4.弹窗消失的思路代码

      1. - (void)removeViews {  
      2.       
      3.     [UIView animateWithDuration:0.2f animations:^{  
      4.           
      5.         self.blackView.alpha       = 0.f;  
      6.         self.messageView.alpha     = 0.f;  
      7.         self.messageView.transform = CGAffineTransformMakeScale(0.75f, 0.75f);  
      8.           
      9.     } completion:^(BOOL finished) {  
      10.           
      11.         [self removeFromSuperview];  
      12.     }];  
  • 相关阅读:
    nginx-1.8.1的安装
    ElasticSearch 在3节点集群的启动
    The type java.lang.CharSequence cannot be resolved. It is indirectly referenced from required .class files
    sqoop导入导出对mysql再带数据库test能跑通用户自己建立的数据库则不行
    LeetCode 501. Find Mode in Binary Search Tree (找到二叉搜索树的众数)
    LeetCode 437. Path Sum III (路径之和之三)
    LeetCode 404. Sum of Left Leaves (左子叶之和)
    LeetCode 257. Binary Tree Paths (二叉树路径)
    LeetCode Questions List (LeetCode 问题列表)- Java Solutions
    LeetCode 561. Array Partition I (数组分隔之一)
  • 原文地址:https://www.cnblogs.com/LiuChengLi/p/5916375.html
Copyright © 2011-2022 走看看