IOS 动画组

//

//  ViewController.m

//  动画组

//

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

//  Copyright © 2015 崔晓宇. All rights reserved.

//


#import "ViewController.h"


@interface ViewController ()


@end


@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


你可能感兴趣的:(IOS 动画组)