• 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

    细节

  • 相关阅读:
    网站中使用了Excel组件问题 Microsoft.ACE.OLEDB.14.0' provider is not registered on the local machine
    键值对在架构设计里的应用
    轻轻松松 用U盘安装WIN7
    U盘装WIN7:微软官方工具《Windows 7 USB DVD Download Tool》U盘装wind7(更新官方整合SP1的WIN7 ISO)
    微软一站式示例代码库(中文版)20110924版本, 新添加ASP.NET, Windows Base, Silverlight, WinForm等20个Sample
    最薄笔记本苹果MacBook Air安装雪豹+Win7双系统的驱动解决方法
    使用受保护的配置加密配置信息
    自动加密web.config配置节批处理
    Asp.net MVC3学习
    周老师科研站
  • 原文地址:https://www.cnblogs.com/YouXianMing/p/5143468.html
Copyright © 2020-2023  润新知