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的使用的更多相关文章

  1. CASpringAnimation

    iOS9新出现的 /** Subclass for mass-spring animations. */ @interface CASpringAnimation : CABasicAnimation ...

  2. iOS9 CASpringAnimation 弹簧动画详解

    http://blog.csdn.net/zhao18933/article/details/47110469 1. CASpringAnimation iOS9才引入的动画类,它继承于CABaseA ...

  3. iOS进阶_动画的多种实现方式

    一.UIView动画 //UIView动画有开始beginAnimation,有结束commitAnimation    //第一步:开始UIView动画    [UIView beginAnimat ...

  4. CoreAnimation方法汇总

    使用CoreAnimation一般分为三个部分:1.创建执行动画的CALayer 2.创建动画 3.CALayer 添加Animation CoreAnimation是以锚点为基础. CoreAnim ...

  5. 【原】iOS学习44之动画

    1. 简单动画 1> UIImageView GIF 动画 GIF图的原理是:获取图片,存储在图片数组中,按照图片数组的顺序将图片以一定的速度播放 UIImageView *showGifima ...

  6. CoreAnimation动画(CALayer动画)

    #pragma mark - CABasicAnimation动画 - (IBAction)basicAnimation:(UIButton *)sender { // 1.创建动画对象 CABasi ...

  7. github上所有大于800 star OC框架

    https://github.com/XCGit/awesome-objc-frameworks#awesome-objc-frameworks awesome-objc-frameworks ID ...

  8. UI进阶 动画

    前言:所谓动画,即应用界面上展示的各种过渡效果,不过其实没有动画并不影响我们产品的功能实现 一.动画 1.动画可以达到的效果 传达状态 提高用户对直接操作的感知 帮助用户可视化操作的结果 2.使用动画 ...

  9. iOS开发——图形编程OC篇&粘性动画以及果冻效果

    粘性动画以及果冻效果 在最近做个一个自定义PageControl——KYAnimatedPageControl中,我实现了CALayer的形变动画以及CALayer的弹性动画,效果先过目: 先做个提纲 ...

随机推荐

  1. Ionic Js十一:模态

    ionicModal 可以遮住用户主界面的内容框. 你可以在你的 index 文件或者是其他文件内嵌入以下代码(里面的代码可以根据你自己的业务场景相应的改变). <script id=" ...

  2. java jdbc深入理解(connection与threadlocal与数据库连接池和事务实)

    1.jdbc连接数据库,就这样子 Class.forName("com.mysql.jdbc.Driver");java.sql.Connection conn = DriverM ...

  3. 美团外卖Android平台化的复用实践

    美团外卖平台化复用主要是指多端代码复用,正如美团外卖iOS多端复用的推动.支撑与思考文章所述,多端包含有两层意思:其一是相同业务的多入口,指美团外卖业务需要在美团外卖App(下文简称外卖App)和美团 ...

  4. 说一说Servlet的生命周期

    servlet有良好的生存期的定义,包括加载和实例化.初始化.处理请求以及服务结束.这个生存期由javax.servlet.Servlet接口的init,service和destroy方法表达. Se ...

  5. Here is a 10-line template that can solve most 'substring' problems子字符串问题的模板

    转载自leetcode评论区:https://discuss.leetcode.com/topic/30941/here-is-a-10-line-template-that-can-solve-mo ...

  6. Python如何将RGB图像转换为Pytho灰度图像?

    我正尝试使用matplotlib读取RGB图像并将其转换为灰度.在matlab中,我使用这个: 1 img = rgb2gray(imread('image.png')); 在matplotlib t ...

  7. springBoot 自动配置原理

    在之前文章中说过,springBoot会根据jar包去添加许多的自动配置,本文就来说说为什么会自动配置,自动配置的原理时什么? springBoot在运行SpringApplication对象实例化时 ...

  8. 汉化 的 空指针 bug

    韩梦飞沙  韩亚飞  313134555@qq.com  yue31313  han_meng_fei_sha nulljava.lang.NullPointerException at com.an ...

  9. EL表达式和JSTL标准标签库

    一.EL表达式 什么是EL表达式 EL(Express Lanuage)表达式可以嵌入在jsp页面内部 减少jsp脚本的编写 EL出现的目的是要替代jsp页面中脚本的编写. EL表达式的作用 EL最主 ...

  10. Alpha7

    难受