POPSpring动画参数详解

效果

源码

https://github.com/YouXianMing/Animations

  1. //
  2. // POPSpringParameterController.m
  3. // Animations
  4. //
  5. // Created by YouXianMing on 15/11/29.
  6. // Copyright © 2015年 YouXianMing. All rights reserved.
  7. //
  8.  
  9. #import "POPSpringParameterController.h"
  10. #import "RangeValueView.h"
  11. #import "UIView+SetRect.h"
  12. #import "POP.h"
  13. #import "FontAttribute.h"
  14. #import "ForegroundColorAttribute.h"
  15. #import "NSMutableAttributedString+StringAttribute.h"
  16.  
  17. #define Width [UIScreen mainScreen].bounds.size.width
  18. #define Height [UIScreen mainScreen].bounds.size.height
  19.  
  20. @interface POPSpringParameterController ()
  21.  
  22. @property (nonatomic, strong) UILabel *secondsLabel;
  23. @property (nonatomic, strong) NSDate *dateStart;
  24.  
  25. @property (nonatomic, strong) RangeValueView *rangeSpeed;
  26. @property (nonatomic, strong) RangeValueView *rangeBounciness;
  27. @property (nonatomic, strong) RangeValueView *rangeMass;
  28. @property (nonatomic, strong) RangeValueView *rangeFriction;
  29. @property (nonatomic, strong) RangeValueView *rangeTension;
  30.  
  31. @property (nonatomic, strong) UIButton *showView;
  32.  
  33. @end
  34.  
  35. @implementation POPSpringParameterController
  36.  
  37. - (void)viewDidLoad {
  38.  
  39. [super viewDidLoad];
  40. }
  41.  
  42. - (void)setup {
  43.  
  44. [super setup];
  45.  
  46. [self initSecondLabel];
  47.  
  48. [self initButton];
  49.  
  50. [self initRangeViews];
  51.  
  52. [self bringTitleViewToFront];
  53. }
  54.  
  55. - (void)initSecondLabel {
  56.  
  57. self.secondsLabel = [[UILabel alloc] initWithFrame:CGRectMake(, + , , )];
  58. self.secondsLabel.attributedText = [self stringWithFloat:.f];
  59. [self.view addSubview:self.secondsLabel];
  60. }
  61.  
  62. - (NSAttributedString *)stringWithFloat:(CGFloat)value {
  63.  
  64. // 字符串
  65. NSString *stringValue = [NSString stringWithFormat:@"%.2f", value];
  66. NSString *secondString = [NSString stringWithFormat:@"seconds"];
  67. NSString *totalString = [NSString stringWithFormat:@"%@ %@", stringValue, secondString];
  68.  
  69. // 字体
  70. UIFont *allFont = Font_Avenir();
  71. UIFont *numFont = Font_Avenir_Light();
  72.  
  73. FontAttribute *totalFont = [FontAttribute new];
  74. totalFont.font = allFont;
  75. totalFont.effectRange = NSMakeRange(, totalString.length);
  76.  
  77. FontAttribute *valueFont = [FontAttribute new];
  78. valueFont.font = numFont;
  79. valueFont.effectRange = [totalString rangeOfString:stringValue];
  80.  
  81. ForegroundColorAttribute *textColor = [ForegroundColorAttribute new];
  82. textColor.color = [UIColor grayColor];
  83. textColor.effectRange = NSMakeRange(, totalString.length);
  84.  
  85. ForegroundColorAttribute *numColor = [ForegroundColorAttribute new];
  86. numColor.color = [UIColor blackColor];
  87. numColor.effectRange = [totalString rangeOfString:stringValue];
  88.  
  89. NSMutableAttributedString *attributeString = [[NSMutableAttributedString alloc] initWithString:totalString];
  90. [attributeString addStringAttribute:totalFont];
  91. [attributeString addStringAttribute:valueFont];
  92. [attributeString addStringAttribute:textColor];
  93. [attributeString addStringAttribute:numColor];
  94.  
  95. return attributeString;
  96. }
  97.  
  98. - (void)initButton {
  99.  
  100. CGFloat gap = Height - - * - ;
  101.  
  102. CGFloat width = .f;
  103. self.showView = [[UIButton alloc] initWithFrame:CGRectMake(, , width, width)];
  104. self.showView.center = CGPointMake(self.view.middleX, + gap / .f);
  105. self.showView.backgroundColor = [UIColor cyanColor];
  106. self.showView.layer.cornerRadius = self.showView.width / .f;
  107. [self.view addSubview:self.showView];
  108. [self.showView addTarget:self
  109. action:@selector(doAnimation)
  110. forControlEvents:UIControlEventTouchUpInside];
  111. }
  112.  
  113. - (void)doAnimation {
  114.  
  115. // 移除动画
  116. [self.showView.layer pop_removeAllAnimations];
  117.  
  118. POPSpringAnimation *spring = [POPSpringAnimation animationWithPropertyNamed:kPOPLayerScaleXY];
  119.  
  120. // 设置代理
  121. spring.delegate = self;
  122.  
  123. // 动画起始值 + 动画结束值
  124. spring.fromValue = [NSValue valueWithCGSize:CGSizeMake(.f, .f)];
  125. spring.toValue = [NSValue valueWithCGSize:CGSizeMake(.f, .f)];
  126.  
  127. // 参数的设置
  128. spring.springSpeed = self.rangeSpeed.currentValue;
  129. spring.springBounciness = self.rangeBounciness.currentValue;
  130. spring.dynamicsMass = self.rangeMass.currentValue;
  131. spring.dynamicsFriction = self.rangeFriction.currentValue;
  132. spring.dynamicsTension = self.rangeTension.currentValue;
  133.  
  134. // 执行动画
  135. [self.showView.layer pop_addAnimation:spring forKey:nil];
  136. }
  137.  
  138. - (void)pop_animationDidStart:(POPAnimation *)anim {
  139.  
  140. self.dateStart = [NSDate date];
  141. }
  142.  
  143. - (void)pop_animationDidApply:(POPAnimation *)anim {
  144.  
  145. CGFloat seconds = -[self.dateStart timeIntervalSinceNow];
  146. self.secondsLabel.attributedText = [self stringWithFloat:seconds];
  147. }
  148.  
  149. - (void)pop_animationDidStop:(POPAnimation *)anim finished:(BOOL)finished {
  150.  
  151. CGFloat seconds = -[self.dateStart timeIntervalSinceNow];
  152. self.secondsLabel.attributedText = [self stringWithFloat:seconds];
  153. }
  154.  
  155. - (void)initRangeViews {
  156.  
  157. self.rangeSpeed = [RangeValueView rangeValueViewWithFrame:CGRectMake(, Height - , Width - , )
  158. name:@"速度 Speed"
  159. minValue:.f
  160. maxValue:.f
  161. defaultValue:.f];
  162. [self.view addSubview:self.rangeSpeed];
  163.  
  164. self.rangeBounciness = [RangeValueView rangeValueViewWithFrame:CGRectMake(, Height - - , Width - , )
  165. name:@"弹力 Bounciness"
  166. minValue:.f
  167. maxValue:.f
  168. defaultValue:.f];
  169. [self.view addSubview:self.rangeBounciness];
  170.  
  171. self.rangeMass = [RangeValueView rangeValueViewWithFrame:CGRectMake(, Height - - *, Width - , )
  172. name:@"质量 Mass"
  173. minValue:0.1
  174. maxValue:.f
  175. defaultValue:.f];
  176. [self.view addSubview:self.rangeMass];
  177.  
  178. self.rangeFriction = [RangeValueView rangeValueViewWithFrame:CGRectMake(, Height - - *, Width - , )
  179. name:@"摩擦 Friction"
  180. minValue:
  181. maxValue:
  182. defaultValue:30.486980];
  183. [self.view addSubview:self.rangeFriction];
  184.  
  185. self.rangeTension = [RangeValueView rangeValueViewWithFrame:CGRectMake(, Height - - *, Width - , )
  186. name:@"拉力 Tension"
  187. minValue:
  188. maxValue:
  189. defaultValue:];
  190. [self.view addSubview:self.rangeTension];
  191. }
  192.  
  193. @end

细节

POPSpring动画参数详解的更多相关文章

  1. iOS:核心动画的详解介绍:CAAnimation(抽象类)及其子类

    核心动画的详解介绍:CAAnimation(抽象类)   1.核心动画基本概念 Core Animation是一组非常强大的动画处理API,使用它能做出非常炫丽的动画效果,而且往往是事半功倍! 使用它 ...

  2. Android Animations 视图动画使用详解!!!

    转自:http://www.open-open.com/lib/view/open1335777066015.html Android Animations 视图动画使用详解 一.动画类型 Andro ...

  3. VLC命令行参数详解

    VLC命令行参数详解 2012-11-29 14:00 6859人阅读 评论(0) 收藏 举报 Usage: vlc [options] [stream] ...You can specify mul ...

  4. Android基础夯实--重温动画(五)之属性动画 ObjectAnimator详解

    只有一种真正的英雄主义 一.摘要 ObjectAnimator是ValueAnimator的子类,它和ValueAnimator一样,同样具有计算属性值的功能,但对比ValueAnimator,它会更 ...

  5. Nginx主配置参数详解,Nginx配置网站

    1.Niginx主配置文件参数详解 a.上面博客说了在Linux中安装nginx.博文地址为:http://www.cnblogs.com/hanyinglong/p/5102141.html b.当 ...

  6. iptables参数详解

    iptables参数详解 搬运工:尹正杰 注:此片文章来源于linux社区. Iptalbes 是用来设置.维护和检查Linux内核的IP包过滤规则的. 可以定义不同的表,每个表都包含几个内部的链,也 ...

  7. chattr的常用参数详解

    chattr的常用参数详解 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 在实际生产环境中,有的运维工程师不得不和开发和测试打交道,在我们公司最常见的就是部署接口.每天每个人部署的 ...

  8. mha配置参数详解

    mha配置参数详解: 参数名字 是否必须 参数作用域 默认值 示例 hostname Yes Local Only - hostname=mysql_server1, hostname=192.168 ...

  9. $.ajax()方法所有参数详解;$.get(),$.post(),$.getJSON(),$.ajax()详解

    [一]$.ajax()所有参数详解 url: 要求为String类型的参数,(默认为当前页地址)发送请求的地址. type: 要求为String类型的参数,请求方式(post或get)默认为get.注 ...

随机推荐

  1. WORDPRESS登录后台半天都无法访问或者是访问慢的解决方法

    wordpress登录后台如果打开速度慢,一般分为两部分,第一部分是php虚拟主机的原因,其中主机的原因,又分为很多种情况.第二部分就是WordPress程序本身的问题.这里无忧主机小编主要是讲第二部 ...

  2. FileBeat读取特征目录及特征文件,为不同的path生成不同的Kafka Topic

    进入日志收集及监控报警这个领域,感觉一切都要从新学习. 现在周五,这周有两天用来踩坑了. 作些记录. 第一个遇到的问题,就是不同的应用组件,在k8s里,会生成不同的日志,如何采集到这些不同的日志呢? ...

  3. JAVA类课后练习

    1.Pg168--2 package com.hanqi; import java.util.Scanner; public class Rectangle { Rectangle() { //完成初 ...

  4. CCF CSP 201509-4 高速公路

    CCF计算机职业资格认证考试题解系列文章为meelo原创,请务必以链接形式注明本文地址 CCF CSP 201509-4 高速公路 问题描述 某国有n个城市,为了使得城市间的交通更便利,该国国王打算在 ...

  5. 【LOJ】#2063. 「HAOI2016」字符合并

    题解 dp[i][j][S]表示区间[i,j]内剩余的数位状压后为S的最大值 这样转移起来不就是\(n^3 2^8\)了吗 冷静一下,我们可以发现一段区间内剩下的数位的个数是一定的,也就是我们可以在枚 ...

  6. JS 如何准确获取当前页面URL网址信息

    在WEB开发中,时常会用到javascript来获取当前页面的url网址信息,在这里是一些获取url信息的小总结. 下面我们举例一个URL,然后获得它的各个组成部分:http://i.cnblogs. ...

  7. Gitlab Issue Tracker and Wiki(二)

    一. 引用问题 1. 登陆 Gitlab服务器 2. 进入到super-git项目 3. 创建一个问题 4. 查看创建问题的号码,可以在下图找到. 5. 对代码进行提交去关闭这个问题,首先把项目在本机 ...

  8. 安卓RecylerView嵌套和事件处理

    最近遇到了一个需求:RecylerView的某一项为listView,即listView嵌套,且要求内部ListView可以滑动,高度固定. 如果直接简单的写完,会发现有两个问题: 1.内部listV ...

  9. window.open()/剪切板ZeroClipboard

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  10. 关于mysql_connect CLIENT_MULTI_RESULTS

    自己写了一个mysql存储过程,以为php有用于调用存储过程的内建函数,查了一下发现只能用mysql_query(call pro())这样的方式,我认为从本质上也就相当于在mysql命令行里执行语句 ...