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(, + , , )];
self.secondsLabel.attributedText = [self stringWithFloat:.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();
UIFont *numFont = Font_Avenir_Light(); FontAttribute *totalFont = [FontAttribute new];
totalFont.font = allFont;
totalFont.effectRange = NSMakeRange(, 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(, 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 - - * - ; CGFloat width = .f;
self.showView = [[UIButton alloc] initWithFrame:CGRectMake(, , width, width)];
self.showView.center = CGPointMake(self.view.middleX, + gap / .f);
self.showView.backgroundColor = [UIColor cyanColor];
self.showView.layer.cornerRadius = self.showView.width / .f;
[self.view addSubview:self.showView];
[self.showView addTarget:self
action:@selector(doAnimation)
forControlEvents:UIControlEventTouchUpInside];
} - (void)doAnimation { // 移除动画
[self.showView.layer pop_removeAllAnimations]; POPSpringAnimation *spring = [POPSpringAnimation animationWithPropertyNamed:kPOPLayerScaleXY]; // 设置代理
spring.delegate = self; // 动画起始值 + 动画结束值
spring.fromValue = [NSValue valueWithCGSize:CGSizeMake(.f, .f)];
spring.toValue = [NSValue valueWithCGSize:CGSizeMake(.f, .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(, Height - , Width - , )
name:@"速度 Speed"
minValue:.f
maxValue:.f
defaultValue:.f];
[self.view addSubview:self.rangeSpeed]; self.rangeBounciness = [RangeValueView rangeValueViewWithFrame:CGRectMake(, Height - - , Width - , )
name:@"弹力 Bounciness"
minValue:.f
maxValue:.f
defaultValue:.f];
[self.view addSubview:self.rangeBounciness]; self.rangeMass = [RangeValueView rangeValueViewWithFrame:CGRectMake(, Height - - *, Width - , )
name:@"质量 Mass"
minValue:0.1
maxValue:.f
defaultValue:.f];
[self.view addSubview:self.rangeMass]; self.rangeFriction = [RangeValueView rangeValueViewWithFrame:CGRectMake(, Height - - *, Width - , )
name:@"摩擦 Friction"
minValue:
maxValue:
defaultValue:30.486980];
[self.view addSubview:self.rangeFriction]; self.rangeTension = [RangeValueView rangeValueViewWithFrame:CGRectMake(, Height - - *, Width - , )
name:@"拉力 Tension"
minValue:
maxValue:
defaultValue:];
[self.view addSubview:self.rangeTension];
} @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. SSIS 学习之旅 数据同步

    这一章 别人也有写过但是我觉得还是写写比较好.数据同步其实就是想仿照 数据库的发布订阅功能 第一章:SSIS 学习之旅 第一个SSIS 示例(一)(上) 第二章:SSIS 学习之旅 第一个SSIS 示 ...

  2. C# 在RichTextBox根据内容自动调整高度

    private void richTextBox1_ContentsResized(object sender, ContentsResizedEventArgs e)   {   richTextB ...

  3. 【51nod】1061 最复杂的数 V2

    题解 我是榜上最后一名= = 可能高精度用vector太慢了吧--什么破题= = 这道题很简单,如果高精度熟练代码--也很简单--然而,参数调了好久 我们发现质数的指数一定是,质数越小,指数越大,这个 ...

  4. css如何画出类似原生的线条?

    做前端的程序猿特别是移动端的,都很头疼遇到一种情况就是需要div底部加一个线条但是 1px的效果很粗,跟设计案上的不符合. 我的一个伙伴查找出来的一个解决方法: 在需要加上的线条的地方加上一个div ...

  5. 在VMware虚拟机中安装Mac OS 操作系统

    1. 安装VMware 我这里是安装VMWARE12.exe,其他的版本我不知道是否可以正常运行,最好大家安装12版本的比较好. 2. 安装 Mac OS X Unlocker for VMware ...

  6. hdoj1171 Big Event in HDU(01背包 || 多重背包)

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1171 题意 老师有一个属性:价值(value).在学院里的老师共有n种价值,每一种价值value对应着 ...

  7. ubuntu 14.04 Bob 安装

    1. 附件依赖项安装$ sudo add-apt-repository ppa:biometrics/bob $ sudo apt-get update $ sudo apt-get install ...

  8. Hadoop CapacitySchedule配置

    下面是Hadoop中CapacitySchedule配置,包含了新建队列和子队列 <configuration> <property> <name>yarn.sch ...

  9. Android中selector背景选择器

    http://blog.csdn.net/forsta/article/details/26148403 http://blog.csdn.net/wswqiang/article/details/6 ...

  10. 跑对抗样本库 CleverHans 的例子时,遇到的问题

    环境:Ubuntu+TensorFlow 首先是GPU被其他人占用了,怎么也跑不起来最简单的TensorFlow小例子. 所以先学会如何查看显卡使用情况,转去使用其他空闲显卡. Linux查看Nvid ...