POPSpring动画参数详解

效果

源码

https://github.com/YouXianMing/Animations

//
//  POPSpringParameterController.m
//  Animations
//
//  Created by YouXianMing on 15/11/29.
//  Copyright © 2015年 YouXianMing. All rights reserved.
//

#import "POPSpringParameterController.h"
#import "RangeValueView.h"
#import "UIView+SetRect.h"
#import "POP.h"
#import "FontAttribute.h"
#import "ForegroundColorAttribute.h"
#import "NSMutableAttributedString+StringAttribute.h"#define  Width   [UIScreen mainScreen].bounds.size.width
#define  Height  [UIScreen mainScreen].bounds.size.height@interface POPSpringParameterController ()@property (nonatomic, strong) UILabel  *secondsLabel;
@property (nonatomic, strong) NSDate   *dateStart;@property (nonatomic, strong) RangeValueView *rangeSpeed;
@property (nonatomic, strong) RangeValueView *rangeBounciness;
@property (nonatomic, strong) RangeValueView *rangeMass;
@property (nonatomic, strong) RangeValueView *rangeFriction;
@property (nonatomic, strong) RangeValueView *rangeTension;@property (nonatomic, strong) UIButton *showView;@end@implementation POPSpringParameterController- (void)viewDidLoad {[super viewDidLoad];
}- (void)setup {[super setup];[self initSecondLabel];[self initButton];[self initRangeViews];[self bringTitleViewToFront];
}- (void)initSecondLabel {self.secondsLabel                = [[UILabel alloc] initWithFrame:CGRectMake(10, 10 + 64, 100, 20)];self.secondsLabel.attributedText = [self stringWithFloat:0.f];[self.view addSubview:self.secondsLabel];
}- (NSAttributedString *)stringWithFloat:(CGFloat)value {// 字符串NSString *stringValue  = [NSString stringWithFormat:@"%.2f", value];NSString *secondString = [NSString stringWithFormat:@"seconds"];NSString *totalString  = [NSString stringWithFormat:@"%@ %@", stringValue, secondString];// 字体UIFont *allFont        = Font_Avenir(12);UIFont *numFont        = Font_Avenir_Light(20);FontAttribute *totalFont = [FontAttribute new];totalFont.font           = allFont;totalFont.effectRange    = NSMakeRange(0, totalString.length);FontAttribute *valueFont = [FontAttribute new];valueFont.font           = numFont;valueFont.effectRange    = [totalString rangeOfString:stringValue];ForegroundColorAttribute *textColor = [ForegroundColorAttribute new];textColor.color                     = [UIColor grayColor];textColor.effectRange               = NSMakeRange(0, totalString.length);ForegroundColorAttribute *numColor = [ForegroundColorAttribute new];numColor.color                     = [UIColor blackColor];numColor.effectRange               = [totalString rangeOfString:stringValue];NSMutableAttributedString *attributeString = [[NSMutableAttributedString alloc] initWithString:totalString];[attributeString addStringAttribute:totalFont];[attributeString addStringAttribute:valueFont];[attributeString addStringAttribute:textColor];[attributeString addStringAttribute:numColor];return attributeString;
}- (void)initButton {CGFloat gap = Height - 60 - 40*4 - 64;CGFloat width                    = 100.f;self.showView                    = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, width, width)];self.showView.center             = CGPointMake(self.view.middleX, 64 + gap / 2.f);self.showView.backgroundColor    = [UIColor cyanColor];self.showView.layer.cornerRadius = self.showView.width / 2.f;[self.view addSubview:self.showView];[self.showView addTarget:selfaction:@selector(doAnimation)forControlEvents:UIControlEventTouchUpInside];
}- (void)doAnimation {// 移除动画
    [self.showView.layer pop_removeAllAnimations];POPSpringAnimation *spring = [POPSpringAnimation animationWithPropertyNamed:kPOPLayerScaleXY];// 设置代理spring.delegate            = self;// 动画起始值 + 动画结束值spring.fromValue           = [NSValue valueWithCGSize:CGSizeMake(1.f, 1.f)];spring.toValue             = [NSValue valueWithCGSize:CGSizeMake(2.f, 2.f)];// 参数的设置spring.springSpeed         = self.rangeSpeed.currentValue;spring.springBounciness    = self.rangeBounciness.currentValue;spring.dynamicsMass        = self.rangeMass.currentValue;spring.dynamicsFriction    = self.rangeFriction.currentValue;spring.dynamicsTension     = self.rangeTension.currentValue;// 执行动画
    [self.showView.layer pop_addAnimation:spring forKey:nil];
}- (void)pop_animationDidStart:(POPAnimation *)anim {self.dateStart = [NSDate date];
}- (void)pop_animationDidApply:(POPAnimation *)anim {CGFloat seconds                  = -[self.dateStart timeIntervalSinceNow];self.secondsLabel.attributedText = [self stringWithFloat:seconds];
}- (void)pop_animationDidStop:(POPAnimation *)anim finished:(BOOL)finished {CGFloat seconds                  = -[self.dateStart timeIntervalSinceNow];self.secondsLabel.attributedText = [self stringWithFloat:seconds];
}- (void)initRangeViews {self.rangeSpeed = [RangeValueView rangeValueViewWithFrame:CGRectMake(10, Height - 60, Width - 20, 0)name:@"速度  Speed"minValue:0.fmaxValue:20.fdefaultValue:12.f];[self.view addSubview:self.rangeSpeed];self.rangeBounciness = [RangeValueView rangeValueViewWithFrame:CGRectMake(10, Height - 60 - 40, Width - 20, 0)name:@"弹力  Bounciness"minValue:0.fmaxValue:20.fdefaultValue:4.f];[self.view addSubview:self.rangeBounciness];self.rangeMass = [RangeValueView rangeValueViewWithFrame:CGRectMake(10, Height - 60 - 40*2, Width - 20, 0)name:@"质量  Mass"minValue:0.1maxValue:10.fdefaultValue:1.f];[self.view addSubview:self.rangeMass];self.rangeFriction = [RangeValueView rangeValueViewWithFrame:CGRectMake(10, Height - 60 - 40*3, Width - 20, 0)name:@"摩擦  Friction"minValue:1maxValue:50defaultValue:30.486980];[self.view addSubview:self.rangeFriction];self.rangeTension = [RangeValueView rangeValueViewWithFrame:CGRectMake(10, Height - 60 - 40*4, Width - 20, 0)name:@"拉力  Tension"minValue:1maxValue:1000defaultValue:300];[self.view addSubview:self.rangeTension];
}@end

细节

POPSpring动画参数详解相关推荐

  1. Android 动画框架详解,第 1 部分

    2019独角兽企业重金招聘Python工程师标准>>> Android 平台提供了一套完整的动画框架,使得开发者可以用它来开发各种动画效果,本文将向读者阐述 Android 的动画框 ...

  2. Unity动画系统详解10:子状态机是什么?

    摘要:除了使用Layer还有没有更好的组织状态的方式呢?感觉一个Layer里面状态多的时候,还是很显得很乱. 洪流学堂,让你快人几步.你好,我是跟着大智学Unity的萌新,我叫小新,这是复(yu)习( ...

  3. Unity动画系统详解9:Target Matching是什么?

    摘要:在游戏中,经常有这种情况:角色的手或者脚需要在特定时间放在特定的位置.比如角色需要用手撑着跳过一个石头或一堵墙,或者跳起抓住房梁.Target Match就是让动画的特定片段去匹配特定的位置. ...

  4. Unity动画系统详解5:BlendTree混合树是什么?

    摘要:"Animator中有一个功能,用来解决多个动画之间的混合,经常用于移动动画之间的混合,这个功能叫做BlendTree,混合树." 洪流学堂,让你快人几步.你好,我是跟着大智 ...

  5. unity velocity_Unity动画系统详解5:BlendTree混合树是什么?

    摘要:"Animator中有一个功能,用来解决多个动画之间的混合,经常用于移动动画之间的混合,这个功能叫做BlendTree,混合树." 洪流学堂,让你快人几步.你好,我是跟着大智 ...

  6. 窗口发送消息参数详解

    窗口发送消息参数详解 //    窗口.发送消息    函数功能: 将指定的消息发送到一个窗口,同win32 api 里面的SendMessage等同的效果 中文函数原型: 发送消息(hwnd,msg ...

  7. T4M插件放入unity后怎么找不到_Unity动画系统详解4:如何用代码控制动画?

    摘要:通过上一篇咱们知道了播放动画需要使用Animator,那么如何用代码控制动画呢? 洪流学堂,让你快人几步.你好,我是跟着大智学Unity的萌新,我叫小新,这几周一起来复(yu)习(xi)动画系统 ...

  8. Windows 窗口发送消息参数详解

    窗口发送消息参数详解 // 窗口.发送消息 函数功能: 将指定的消息发送到一个窗口,同win32 api 里面的SendMessage等同的效果中文函数原型: 发送消息(hwnd,msg,wparam ...

  9. MOS管工作动画原理图详解

    MOS管工作动画原理图详解 绝缘型场效应管的栅极与源极.栅极和漏极之间均采用SiO2绝缘层隔离,因此而得名.又因栅极为金属铝,故又称为MOS管.它的栅极-源极之间的电阻比结型场效应管大得多,可达101 ...

最新文章

  1. 三星a60android9,三星A6058官方国行安卓9固件rom线刷升级包:CHM-A6058ZMU2BSC9
  2. css之absolute
  3. robot:List变量的使用注意点
  4. 招博后,比利时鲁汶大学 A2H 部计算机视觉动物行为分析方向
  5. 虚拟机访问本地mysql_如何在本地远程连接linux虚拟机上面的mysql
  6. Scala中的Apply方法与伴生对象
  7. 数据库系统的并发控制的两种实现模型
  8. java解决硬编码_工具类 解决硬编码问题
  9. GB28181协议常见几种信令流程(一)
  10. MD4、MD5、SHA1、HMAC、HMAC_SHA1区别
  11. linux数据库可视化工具_适用于Linux的数据可视化工具
  12. 医疗服务机器人市场复合年增长率将达15.7%
  13. 从T7模型中取训练参数
  14. mysql 没有 myd_MySQL中找不到.myd文件的问题
  15. python 线性相关 与 线性拟合
  16. php 文本域,关于使用文本域(TextArea)的一个问题
  17. (python)基于GUI编写摄氏度转华氏度
  18. java 必须try catch的异常_【java基础之异常】死了都要try,不淋漓尽致地catch我不痛快!...
  19. isDebugEnabled作用
  20. 刷酸记录(迪维维A酸乳膏)20190905

热门文章

  1. led灯串怎么摆造型_如何驱动LED灯串小绝招
  2. python 用队列实现栈
  3. @Transactional事务的使用和注意事项及其属性
  4. Halcon知识 : 乘法图像融合
  5. Docker知识4:如何在win10下安装 / 使用ubuntu ?应用WSL2
  6. python结巴分词 词频统计_一个txt文档,已经用结巴分词分完词,怎么用python工具对这个分完词的文档进行计算统计词频,求脚本,非...
  7. 2021-03-16 汽车二自由度操纵稳定性 Matlab simulink
  8. axure 如何设置选项联动_Axure下拉框级联操作
  9. Java 守护线程概述
  10. 《maven官方文档》5分钟开始Maven