当前位置:小鱼儿玄机二站 > 操作系统 > 弹簧动画二

弹簧动画二

文章作者:操作系统 上传时间:2019-11-25

核心动漫——弹簧动漫二,核心动漫弹簧

主导动漫——弹簧动漫生龙活虎主要介绍弹簧动漫的部分性质,上边介绍一下弹簧动漫的另意气风发种效应。

先是在Main.storyboard文件之中创立二个UIButton,ViewController世襲于ViewController。将UIButton设置为壹性情质,选中UIButton右击不放手扶拖沓机到ViewController.m文件的@interface 里面并给它起名。相同的时间,给它三个接触事件,将它拖到@implementation里面。具体操作看代码:

#import "ViewController.h"

@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIButton *annimationButton;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

}

- (IBAction)action:(id)sender {

    UIButton *button = sender;
    button.selected = !button.selected;
    button.backgroundColor = button.selected != YES?[UIColor colorWithRed:1.000 green:0.435 blue:0.812 alpha:1.000]:[UIColor colorWithRed:0.400 green:0.800 blue:1.000 alpha:1.000];
    [self jump];
}

- (void)jump{
    CASpringAnimation *animation = [CASpringAnimation animationWithKeyPath:@"bounds"];
    animation.toValue = [NSValue valueWithCGRect:CGRectMake(0, 0, self.annimationButton.frame.size.width*1.5, self.annimationButton.frame.size.height*1.5)];
    animation.mass = 2;
    animation.stiffness = 100;
    animation.damping = 3;
    animation.initialVelocity = 30;
    animation.duration = animation.settlingDuration;
    [self.annimationButton.layer addAnimation:animation forKey:@"jump"];

}

- (void)move:(CGPoint)toPoint{

    CABasicAnimation *basicAnimation = [CABasicAnimation animationWithKeyPath:@"position"];
    basicAnimation.toValue = [NSValue valueWithCGPoint:toPoint];
    basicAnimation.duration = 3;
    basicAnimation.removedOnCompletion = NO;
    basicAnimation.fillMode = kCAFillModeBoth;
    [self.annimationButton.layer addAnimation:basicAnimation forKey:@"move"];

}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{

    [self move:[[touches anyObject] locationInView:self.view]];
    NSLog(@"button改变位置之前的中心点x:%f y:%f",self.annimationButton.center.x,self.annimationButton.center.y);
    NSLog(@"button上面Layer的中心点x:%f y:%f",self.annimationButton.layer.position.x,self.annimationButton.layer.position.y);
    //CAAnimation 只是改变图层的动画效果,并没有真实的改变视图、图层的属性值

}
@end

它的功力便是点击button的时候它会变颜色,並且弹跳。

大旨动漫弹簧动漫大器晚成根本介绍弹簧动漫的片段性质,上面介绍一下弹簧动画的另风姿浪漫种成效。 首先...

本文由小鱼儿玄机二站发布于操作系统,转载请注明出处:弹簧动画二

关键词: