動畫屬性總結(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





最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容

  • 在iOS實際開發(fā)中常用的動畫無非是以下四種:UIView動畫,核心動畫,幀動畫,自定義轉場動畫。 1.UIView...
    請叫我周小帥閱讀 3,155評論 1 23
  • 在iOS中隨處都可以看到絢麗的動畫效果,實現這些動畫的過程并不復雜,今天將帶大家一窺ios動畫全貌。在這里你可以看...
    每天刷兩次牙閱讀 8,572評論 6 30
  • 在iOS中隨處都可以看到絢麗的動畫效果,實現這些動畫的過程并不復雜,今天將帶大家一窺iOS動畫全貌。在這里你可以看...
    F麥子閱讀 5,141評論 5 13
  • 顯式動畫 顯式動畫,它能夠對一些屬性做指定的自定義動畫,或者創(chuàng)建非線性動畫,比如沿著任意一條曲線移動。 屬性動畫 ...
    清風沐沐閱讀 1,975評論 1 5
  • 本文轉載自:http://www.cocoachina.com/ios/20150105/10812.html 為...
    idiot_lin閱讀 1,293評論 0 1