CASpringAnimation的使用
CASpringAnimation的使用

效果

源码
https://github.com/YouXianMing/Animations
//
// CASpringAnimationController.m
// Animations
//
// Created by YouXianMing on 16/1/19.
// Copyright © 2016年 YouXianMing. All rights reserved.
// #import "CASpringAnimationController.h"
#import "RangeValueView.h"
#import "WxHxD.h"
#import "UIView+SetRect.h" @interface CASpringAnimationController () @property (nonatomic, strong) UIButton *showView; @property (nonatomic, strong) RangeValueView *stiffnessView;
@property (nonatomic, strong) RangeValueView *dampingView;
@property (nonatomic, strong) RangeValueView *massView;
@property (nonatomic, strong) RangeValueView *initialVelocityView; @end @implementation CASpringAnimationController - (void)setup { [super setup]; [self initRangeViews]; [self initButton];
} - (void)initButton { CGFloat gap = Height - - * - ; CGFloat width = .f;
self.showView = [[UIButton alloc] initWithFrame:CGRectMake(, , width, width)];
self.showView.center = CGPointMake(self.contentView.middleX, + gap / .f);
self.showView.backgroundColor = [UIColor cyanColor];
self.showView.layer.cornerRadius = width / .f;
self.showView.x = Width / .f - ;
[self.showView addTarget:self action:@selector(doAnimation) forControlEvents:UIControlEventTouchUpInside];
[self.contentView addSubview:self.showView];
} - (void)doAnimation { CASpringAnimation *springAnimation = [CASpringAnimation animationWithKeyPath:@"position.x"];
springAnimation.stiffness = self.stiffnessView.currentValue;
springAnimation.mass = self.massView.currentValue;
springAnimation.damping = self.dampingView.currentValue;
springAnimation.initialVelocity = self.initialVelocityView.currentValue;
springAnimation.duration = springAnimation.settlingDuration; springAnimation.fromValue = @(Width / .f - );
springAnimation.toValue = @(Width / .f + );
self.showView.layer.position = CGPointMake(Width / .f + , self.showView.layer.position.y); [self.showView.layer addAnimation:springAnimation forKey:nil];
} - (void)initRangeViews { self.stiffnessView = [RangeValueView rangeValueViewWithFrame:CGRectMake(, Height - , Width - , )
name:@"硬度 Stiffness"
minValue:.f
maxValue:.f
defaultValue:.f];
[self.contentView addSubview:self.stiffnessView]; self.dampingView = [RangeValueView rangeValueViewWithFrame:CGRectMake(, Height - - , Width - , )
name:@"阻尼 Damping"
minValue:0.1f
maxValue:.f
defaultValue:.f];
[self.contentView addSubview:self.dampingView]; self.massView = [RangeValueView rangeValueViewWithFrame:CGRectMake(, Height - - *, Width - , )
name:@"质量 Mass"
minValue:0.1
maxValue:.f
defaultValue:.f];
[self.contentView addSubview:self.massView]; self.initialVelocityView = [RangeValueView rangeValueViewWithFrame:CGRectMake(, Height - - *, Width - , )
name:@"速度 Velocity"
minValue:-.f
maxValue:.f
defaultValue:.f];
[self.contentView addSubview:self.initialVelocityView];
} @end
细节

CASpringAnimation的使用的更多相关文章
- CASpringAnimation
iOS9新出现的 /** Subclass for mass-spring animations. */ @interface CASpringAnimation : CABasicAnimation ...
- iOS9 CASpringAnimation 弹簧动画详解
http://blog.csdn.net/zhao18933/article/details/47110469 1. CASpringAnimation iOS9才引入的动画类,它继承于CABaseA ...
- iOS进阶_动画的多种实现方式
一.UIView动画 //UIView动画有开始beginAnimation,有结束commitAnimation //第一步:开始UIView动画 [UIView beginAnimat ...
- CoreAnimation方法汇总
使用CoreAnimation一般分为三个部分:1.创建执行动画的CALayer 2.创建动画 3.CALayer 添加Animation CoreAnimation是以锚点为基础. CoreAnim ...
- 【原】iOS学习44之动画
1. 简单动画 1> UIImageView GIF 动画 GIF图的原理是:获取图片,存储在图片数组中,按照图片数组的顺序将图片以一定的速度播放 UIImageView *showGifima ...
- CoreAnimation动画(CALayer动画)
#pragma mark - CABasicAnimation动画 - (IBAction)basicAnimation:(UIButton *)sender { // 1.创建动画对象 CABasi ...
- github上所有大于800 star OC框架
https://github.com/XCGit/awesome-objc-frameworks#awesome-objc-frameworks awesome-objc-frameworks ID ...
- UI进阶 动画
前言:所谓动画,即应用界面上展示的各种过渡效果,不过其实没有动画并不影响我们产品的功能实现 一.动画 1.动画可以达到的效果 传达状态 提高用户对直接操作的感知 帮助用户可视化操作的结果 2.使用动画 ...
- iOS开发——图形编程OC篇&粘性动画以及果冻效果
粘性动画以及果冻效果 在最近做个一个自定义PageControl——KYAnimatedPageControl中,我实现了CALayer的形变动画以及CALayer的弹性动画,效果先过目: 先做个提纲 ...
随机推荐
- **PHP转义Json里的特殊字符的函数
http://www.banghui.org/11332.html 在给一个 App 做 API,从服务器端的 MySQL 取出数据,然后生成 JSON.数据中有个字段叫 content,里面保存了文 ...
- day6作业--游戏人生
本节作业: 熟练使用类和模块,写一个交互性强.有冲突的程序. 思路: 1.各个模块之间的调用关系,如何使用类,各种方法的使用上面: 2.学了类,以为能用来解决所有问题,东西都要写在类里面: 3.下面自 ...
- USACO 6.4 The Primes
The PrimesIOI'94 In the square below, each row, each column and the two diagonals can be read as a f ...
- pandas使用总结
一.pandas简介 Pandas是基于Numpy开发出的,是一款开放源码的BSD许可的Python库,为Python编程语言提供了高性能,易于使用的数据结构和数据分析工具.Pandas用于广泛的领域 ...
- 在PHP中gmtime()与time()区别
localtime是把从1970-1-1零点零分到当前时间系统所偏移的秒数时间转换为本地时间,而gmtime函数转换后的时间没有经过时区变换,是UTC时间.2.说明:此函数获得的tm结构体的时间是日历 ...
- 牛客练习赛1 C - 圈圈
链接:https://www.nowcoder.com/acm/contest/2/C来源:牛客网 题目描述 shy有一个队列a[1], a[2],…,a[n].现在我们不停地把头上的元素放到尾巴上. ...
- CodeForces528A (STLset)
题面 CodeForces 题解 横着切和竖着切是互相不影响的. 假设现在横着切成了很多段,显然此时面积最大的矩形的一边长就是这些段中长度最长的一段.竖着切的也是一样的. 所以就可以用\(set\)来 ...
- 决策树(CART)
CART算法全称是分类回归算法,(Classification And Regression Tree),他与ID3.C4.5的不同在于: 1.既可以处理分类问题又可以处理回归问题 2.使用基尼系数作 ...
- JMS异步消息机制
企业消息系统 Java Message Service 是由 Sun Microsystems 开发的,它为 Java 程序提供一种访问 企业消息系统 的方法.在讨论 JMS 之前,我们分来析一下企业 ...
- [POI2000]Repetitions
题目大意: 求多个字符串的LCS. 思路: 同SPOJ-LCS2,不过因为SPOJ上数据比较水,当时用错误的写法过掉了,这次用正确的写法重新过了一遍. 拓扑排序按照每个状态的len值,用计数排序实现. ...