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的弹性动画,效果先过目: 先做个提纲 ...
随机推荐
- iOS中URL的解码和转义问题
在iOS开发中,使用NSURLConnection去请求google places api时,如果请求的url中包含中文,则返回的结果为空,URL不能被google识别.NSString *_urlS ...
- **CI中使用IN查询(where_in)
注意别漏了$this->db->get(); /** * 匹配用户手机号,返回匹配的用户列表 * @param $column_str 'user_id, user_name, user_ ...
- 使用Oracle数据库,对某个表频繁更新
使用Oracle数据库,对某个表频繁更新,查询时要联合这张表,查询速度非常慢,有什么解决办法? 一般的pc机oracle更新的效率均可达到500+/s, 可能的问题,你更新这个不会是每次都新建jdbc ...
- HTTP Status 500 - Request processing failed; nested exception is org.apache.ibatis.binding.BindingException
在使用Maven工程管理工具整合SSM框架时,Mybatis使用逆向工程生成的pojo,mapper接口及映射文件,把mapper接口和映射文件放在DAO工程的同一级src/main/java目录下. ...
- poj3624 Charm Bracelet(DP,01背包)
题目链接 http://poj.org/problem?id=3624 题意 有n个手镯,每个手镯有两个属性:重量W,需求因子D.还有一个背包,它能装下总重量不超过M的手镯.现在将一些镯子装入背包,求 ...
- caffe fine tune 复制预训练model的参数和freeze指定层参数
复制预训练model的参数,只需要重新copy一个train_val.prototxt.然后把不需要复制的层的名字改一下,如(fc7 -> fc7_new),然后fine tune即可. fre ...
- thinkphp条用函数与类库
手册上说的很冗余,没看懂,下面简单的讲一下具体用法. 函数调用: lib公共函数库叫 common.php App/common/common.php 分组模块下的公共函数库叫 function.ph ...
- .NET之类型转换
说起类型转换大家很容易的就会联想到将int类型转换成float类型或者是将double类型转转成int类型之类的转换.当然这可能是大多数人最先接触到的转换方式,也是最简单的转换方式.所谓转换就是从现有 ...
- 2017 Bangladesh National High School Programming Contest ( National Round, Senior Group ), NHSPC 2017 题解
[题目链接] A. Charm Is Not Always Enough 模拟一下就可以了. #include <bits/stdc++.h> using namespace std; i ...
- Noip模拟题 Matrix [递推,组合数]
Matrix 时间限制: 1 Sec 内存限制: 512 MB 题目描述 小 z 的女朋友送给小 z 一个 n × n 的矩阵.但是矩阵实在太大了,小 z 的女朋友拿不动,只能带给他两个长度为 n ...