zoukankan      html  css  js  c++  java
  • 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 - 60 - 40*4 - 64;
        
        CGFloat width                    = 50.f;
        self.showView                    = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, width, width)];
        self.showView.center             = CGPointMake(self.contentView.middleX, 64 + gap / 2.f);
        self.showView.backgroundColor    = [UIColor cyanColor];
        self.showView.layer.cornerRadius = width / 2.f;
        self.showView.x                  = Width / 2.f - 50;
        [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 / 2.f - 50);
        springAnimation.toValue      = @(Width / 2.f + 50);
        self.showView.layer.position = CGPointMake(Width / 2.f + 50, self.showView.layer.position.y);
        
        [self.showView.layer addAnimation:springAnimation forKey:nil];
    }
    
    - (void)initRangeViews {
        
        self.stiffnessView = [RangeValueView rangeValueViewWithFrame:CGRectMake(10, Height - 60, Width - 20, 0)
                                                                name:@"硬度  Stiffness"
                                                            minValue:10.f
                                                            maxValue:200.f
                                                        defaultValue:100.f];
        [self.contentView addSubview:self.stiffnessView];
        
        
        self.dampingView = [RangeValueView rangeValueViewWithFrame:CGRectMake(10, Height - 60 - 40, Width - 20, 0)
                                                              name:@"阻尼  Damping"
                                                          minValue:0.1f
                                                          maxValue:10.f
                                                      defaultValue:5.f];
        [self.contentView addSubview:self.dampingView];
        
        
        self.massView = [RangeValueView rangeValueViewWithFrame:CGRectMake(10, Height - 60 - 40*2, Width - 20, 0)
                                                           name:@"质量  Mass"
                                                       minValue:0.1
                                                       maxValue:20.f
                                                   defaultValue:1.f];
        [self.contentView addSubview:self.massView];
        
        
        self.initialVelocityView = [RangeValueView rangeValueViewWithFrame:CGRectMake(10, Height - 60 - 40*3, Width - 20, 0)
                                                                      name:@"速度  Velocity"
                                                                  minValue:-20.f
                                                                  maxValue:20.f
                                                              defaultValue:0.f];
        [self.contentView addSubview:self.initialVelocityView];
    }
    
    @end

    细节

  • 相关阅读:
    学习素材、网站
    用 Python脚本生成 Android SALT 扰码
    H面试程序(29):求最大递增数
    常用数据库查询判断表和字段是否存在
    《火球——UML大战需求分析》(第3章 分析业务模型-类图)——3.7 关于对象图
    N个数依次入栈,出栈顺序有多少种
    WIN ERROR:C:WindowsSystem32<LANG_NAME>mstsc.exe.MUI
    大端法和小端法
    freopen()重定向的打开和关闭
    Linux 的 Spinlock 在 MIPS 多核处理器中的设计与实现
  • 原文地址:https://www.cnblogs.com/YouXianMing/p/5143468.html
Copyright © 2011-2022 走看看