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

    细节

  • 相关阅读:
    关于android中透明、半透明、百分比转换
    详解 RestTemplate 操作
    springboot No Identifier specified for entity的解决办法
    Java-Spring-获取Request,Response对象
    java 如何判断操作系统是Linux还是Windows
    Spring中使用Ehcache的方法和注意事项
    Protostuff序列化
    如何使用apache自带的ab压力测试工具
    java 调用 wsdl形式的webservice 示例
    web service 异常
  • 原文地址:https://www.cnblogs.com/YouXianMing/p/5143468.html
Copyright © 2011-2022 走看看