IOS 動畫組

//動畫

//  ViewController.mspa

//  動畫組.net

//3d

//  Created by dc008 on 15/12/22.orm

//  Copyright © 2015 崔曉宇. All rights reserved.get

//animation


#import "ViewController.h"it


@interface ViewController ()io


@end form


@implementation ViewController


- (void)viewDidLoad {

    [super viewDidLoad];

   //初始化一個圖層

    CALayer *_layer = [[CALayer alloc]init];

    _layer.frame = CGRectMake(20, 20, 40, 40);

    _layer.backgroundColor = [UIColor grayColor].CGColor;

    [self.view.layer addSublayer:_layer];

    

    //移動位置的動畫

    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position"];

    animation.toValue = [NSValue valueWithCGPoint:CGPointMake(315, 607)];

    //z軸進行旋轉

    CABasicAnimation *rotateAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];

    rotateAnimation.fromValue = [NSNumber numberWithFloat:0];

    rotateAnimation.toValue = [NSNumber numberWithFloat:6 * M_PI];//旋轉3 一週的弧度是2*M_PI

    

    //layer放大

    CABasicAnimation *scaleAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];//.y.x

    scaleAnimation.fromValue = [NSNumber numberWithFloat:1.0];

    scaleAnimation.toValue = [NSNumber numberWithFloat:3.0];

    

    //把上面的動畫組合起來

    CAAnimationGroup *groupAnimation = [CAAnimationGroup animation];//動畫組初始化

    groupAnimation.autoreverses = YES;

    groupAnimation.repeatCount = HUGE_VALF;

    groupAnimation.duration = 3.0;

    groupAnimation.animations = @[animation,rotateAnimation,scaleAnimation];

    [_layer addAnimation:groupAnimation forKey:@"layerMove"];

}


- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}


@end

相關文章
相關標籤/搜索