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. appium----adb shell输入中文/Emoji表情符(ADBKeyBoard)

    前序 “adb shell input textyoyo“ 可以通过adb 输入英文的文本,由于不支持unicode编码,所以无法输入中文,github上有个国外的大神写了个ADBKeyBoard输入 ...

  2. Ubuntu 17.10开启 root 登陆

    使用过 Ubuntu 的人都知道,Ubuntu 默认是不能以 root 登陆的,但是我们是不是就完全不能使用 root 进行登陆了呢?当然不是,只是我们需要做一些设置.而 Ubuntu 17.10 和 ...

  3. 一步一步学习IdentityServer3 (11) OAuth2

    OAuth中定义了四个Role 资源所有者:这里可以理解为一个用户 资源服务器:如同前面章节中的 Web站点或者WebApi 服务资源站点 客户端:这里是Client,如同Identityserver ...

  4. hdu 1085 有num1个 1 ,num2个 2 ,num3个 5 (母函数)

    有num1个 1 ,num2个 2 ,num3个 5问它们不能组成的最小正整数是谁 样例的母函数 (1+X)(1+X2)(1+X5+X10+X15)展开后 X4的系数为0 Sample Input1 ...

  5. codis+redis集群学习整理(待续)

    Codis 由四部分组成: Codis Proxy (codis-proxy) Codis Manager (codis-config) Codis Redis (codis-server) ZooK ...

  6. Rookey.Frame之实体表单验证

    昨天给大家介绍了实体FluentValidation验证,今天继续给大家介绍表单验证,在Rookey.Frame框架中,表单验证有PrimaryKeyFields字段验证.唯一验证.必填验证.常用验证 ...

  7. USACO 6.3 Cowcycles

    CowcyclesOriginally by Don Gillies [International readers should note that some words are puns on co ...

  8. python获取当前系统的桌面的路径

    一,用内置的winreg(推荐) import winregdef get_desktop():    key = winreg.OpenKey(winreg.HKEY_CURRENT_USER,\  ...

  9. PIPESTATUS 对于ksh 无效

    BASH SHELL中,通常使用 $? 来获取上一条命令的返回码. 对于管道中的命令,使用$?只能获取管道中最后一条命令的返回码,例如 下面的例子中/not/a/valid/filename是一个不存 ...

  10. Python与Django的时区问题

    在编码中牵扯到时间问题的时候,总是容易被时区问题搞混,一直以来,都是反复试验应付过去,今天终于搞清楚了个中缘由,一个心结也得以化解. Python 的时区问题 datetime.today() / d ...