动画属性总结(CAAnimation)

<h3>CAAnimation 有几个子类:</h3>
CABasicAnimation:可以对一些基本的属性进行动画
CAKeyFrameAnimation :帧动画可以画路径让一个视图按照一个路径进行动画
CAAnimationGroup :可以存取一组动画,用来管理动画的类
<h2>前面三个只可以对一个view进行操作</h2>
CATransitionAnimation:过渡动画,可以对一个控制器进行操作使一个视图进入另一个视图。
demo:
<h2>

//
//  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<UITouch *> *)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





最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 在iOS实际开发中常用的动画无非是以下四种:UIView动画,核心动画,帧动画,自定义转场动画。 1.UIView...
    请叫我周小帅阅读 3,179评论 1 23
  • 在iOS中随处都可以看到绚丽的动画效果,实现这些动画的过程并不复杂,今天将带大家一窥ios动画全貌。在这里你可以看...
    每天刷两次牙阅读 8,586评论 6 30
  • 在iOS中随处都可以看到绚丽的动画效果,实现这些动画的过程并不复杂,今天将带大家一窥iOS动画全貌。在这里你可以看...
    F麦子阅读 5,152评论 5 13
  • 显式动画 显式动画,它能够对一些属性做指定的自定义动画,或者创建非线性动画,比如沿着任意一条曲线移动。 属性动画 ...
    清风沐沐阅读 1,990评论 1 5
  • 本文转载自:http://www.cocoachina.com/ios/20150105/10812.html 为...
    idiot_lin阅读 1,307评论 0 1