<h3>CAAnimation 有幾個(gè)子類:</h3>
CABasicAnimation:可以對(duì)一些基本的屬性進(jìn)行動(dòng)畫(huà)
CAKeyFrameAnimation :幀動(dòng)畫(huà)可以畫(huà)路徑讓一個(gè)視圖按照一個(gè)路徑進(jìn)行動(dòng)畫(huà)
CAAnimationGroup :可以存取一組動(dòng)畫(huà),用來(lái)管理動(dòng)畫(huà)的類
<h2>前面三個(gè)只可以對(duì)一個(gè)view進(jìn)行操作</h2>
CATransitionAnimation:過(guò)渡動(dòng)畫(huà),可以對(duì)一個(gè)控制器進(jìn)行操作使一個(gè)視圖進(jìn)入另一個(gè)視圖谊惭。
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