动画属性总结(CAAnimation)

CAAnimation 有几个子类:


CABasicAnimation:可以对一些基本的属性进行动画
CAKeyFrameAnimation :帧动画可以画路径让一个视图按照一个路径进行动画
CAAnimationGroup :可以存取一组动画,用来管理动画的类

前面三个只可以对一个view进行操作


CATransitionAnimation:过渡动画,可以对一个控制器进行操作使一个视图进入另一个视图。
demo:

//
//  ViewController.m
//  CAAnimation
//
//  Created by ios on 16/8/15.
//  Copyright © 2016年 fenglei. All rights reserved.
//

#import "ViewController.h"

@interface ViewController (){
    UIImageView *img;

}

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    
    img = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 100, 200)];
    img.center = self.view.center;
    
    img.image = [UIImage imageNamed:@"1.jpg"];
    [self.view addSubview:img];
    
    
    img.layer.anchorPoint = CGPointMake(0.3, 0.3);
    
    
 
    
    
    
    
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    
//    [self rotation];
//    [self position];
    CAKeyframeAnimation *animation1 = [self position];
    CABasicAnimation *animation2 = [self rotation];
    
    CAAnimationGroup *group = [CAAnimationGroup animation];
    group.animations = @[animation1, animation2];
    group.duration = 3;
    group.repeatCount = MAXFLOAT;
//    group.autoreverses = YES;
    [img.layer addAnimation:group forKey:nil];
    
}
- (CAKeyframeAnimation *)position {
    
    CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
    
    CGMutablePathRef  path = CGPathCreateMutable();
//    CGRect rect = CGRectMake(self.view.center.x, self.view.center.y, 60, 60);
//    CGPathAddEllipseInRect(path, nil, rect);
    
    CGPathAddArc(path, nil, self.view.center.x, self.view.center.y, 100, 0, 2*M_PI, 0);
    animation.path = path;
//    animation.duration = 3;
//    animation.repeatCount = 100;
    
//    [img.layer addAnimation:animation forKey:@"frame"];
    
    return animation;
}

- (CABasicAnimation *)rotation {
    
    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"bounds.size.width"];
    
    //属性
    animation.fromValue = @10;
    animation.toValue = @200;
    
//    animation.duration = 3;
    //    animation.speed = 0.5;
    //    animation.autoreverses = YES;
    //    animation.repeatCount = 100;
    
//    [img.layer addAnimation:animation forKey:@"scale"];
    
    return animation;
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end





你可能感兴趣的:(动画属性总结(CAAnimation))