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

相关文章
相关标签/搜索