//
// ViewController.m
// core
//
// Created by chenvinci on 2017/2/16.
// Copyright ? 2017年 cuijing. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIView *redView;
@property (weak, nonatomic) IBOutlet UIImageView *img;
@property(nonatomic) int iIndex;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.iIndex = 0;
self.redView.layer.anchorPoint = CGPointMake(0, 0);
self.redView.layer.position = CGPointMake(100, 100);
}
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
//平移動畫
CABasicAnimation * moveA = [[CABasicAnimation alloc]init];
moveA.keyPath = @"position";
moveA.byValue = [NSValue valueWithCGPoint:CGPointMake(50, 50)];//每次移動(50腾仅,50)
//bounds動畫
CABasicAnimation * boundA = [CABasicAnimation animation];
boundA.keyPath = @"bounds";
boundA.toValue = [NSValue valueWithCGRect:CGRectMake(0, 0, 40, 40)];
//創(chuàng)建組動畫
CAAnimationGroup*group = [CAAnimationGroup animation];
group.animations = @[moveA,boundA];
group.duration = 3;
//動畫完成時不動
group.removedOnCompletion = NO;
group.fillMode = kCAFillModeForwards;
//添加動畫
[self.img.layer addAnimation:group forKey:nil];
}
-(void)touchesBegan3:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
//創(chuàng)建轉(zhuǎn)場動畫
CATransition* animation1 = [CATransition animation];
NSArray* arr = @[@"cube",@"moveIn",@"reveal",@"pageCurl",@"suckEffect",@"rippleEffect",@"oglFlip"];
if (self.iIndex >= arr.count) {
self.iIndex = 0;
}
animation1.type = arr[self.iIndex];
animation1.subtype = @"fromTop";
self.iIndex++;
//添加動畫
[self.img.layer addAnimation:animation1 forKey:nil];
}
-(void)touchesBegan2:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
//創(chuàng)建關(guān)鍵幀動畫
CAKeyframeAnimation*animation1 = [[CAKeyframeAnimation alloc]init];
animation1.duration = 4;
//設(shè)置動畫屬性 修改position
animation1.keyPath = @"position";
NSValue*v1 = [NSValue valueWithCGPoint:CGPointMake(0, 0)];
NSValue*v2 = [NSValue valueWithCGPoint:CGPointMake(100, 0)];
NSValue*v3 = [NSValue valueWithCGPoint:CGPointMake(100, 100)];
NSValue*v4 = [NSValue valueWithCGPoint:CGPointMake(0, 100)];
NSValue*v5 = [NSValue valueWithCGPoint:CGPointMake(0, 0)];
animation1.values = @[v1,v2,v3,v4,v5];
//設(shè)置各關(guān)鍵幀的時間
NSNumber*t1 = [NSNumber numberWithFloat:0.1];//最大是1
NSNumber*t2 = [NSNumber numberWithFloat:0.2];
NSNumber*t3 = [NSNumber numberWithFloat:0.8];
NSNumber*t4 = [NSNumber numberWithFloat:0.9];
NSNumber*t5 = [NSNumber numberWithFloat:1.0];
animation1.keyTimes = @[t1,t2,t3,t4,t5];
//動畫執(zhí)行完以后是否移除郑口?
animation1.removedOnCompletion = NO;
animation1.fillMode = kCAFillModeForwards;//保持最新狀態(tài)
// 添加動畫
[self.redView.layer addAnimation:animation1 forKey:nil];
}
-(void)touchesBegan1:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
//創(chuàng)建基礎(chǔ)動畫
CABasicAnimation* animation1 = [[CABasicAnimation alloc]init];
//設(shè)置動畫屬性 修改bounds
animation1.keyPath = @"bounds";//改bounds屬性要去掉autolayout
animation1.fromValue = [NSValue valueWithCGRect:CGRectMake(0, 0, 100, 100)];
animation1.toValue = [NSValue valueWithCGRect:CGRectMake(0, 0, 200, 200)];
//設(shè)置動畫屬性 修改position
animation1.keyPath = @"position";
animation1.fromValue = [NSValue valueWithCGPoint:CGPointMake(0, 0)];
animation1.toValue = [NSValue valueWithCGPoint:CGPointMake(100, 100)];
//設(shè)置動畫屬性 修改transform
animation1.keyPath = @"transform.translation.x";
animation1.fromValue = [NSNumber numberWithInt:20];
animation1.toValue = [NSNumber numberWithInt:50];
//設(shè)置代理
animation1.delegate = self;
//設(shè)置時長
animation1.duration = 2;
//動畫執(zhí)行完以后是否移除?
animation1.removedOnCompletion = NO;
animation1.fillMode = kCAFillModeForwards;//保持最新狀態(tài)
// 添加動畫
[self.redView.layer addAnimation:animation1 forKey:nil];
}
- (void)animationDidStart:(CAAnimation *)anim{
NSLog(@"start");
}
- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag{
NSLog(@"stop");
}
@end
核心動畫
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
- 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來眉睹,“玉大人荔茬,你說我怎么就攤上這事≈窈#” “怎么了兔院?”我有些...
- 文/不壞的土叔 我叫張陵,是天一觀的道長站削。 經(jīng)常有香客問我,道長孵稽,這世上最難降的妖魔是什么许起? 我笑而不...
- 正文 為了忘掉前任,我火速辦了婚禮菩鲜,結(jié)果婚禮上园细,老公的妹妹穿的比我還像新娘。我一直安慰自己接校,他們只是感情好猛频,可當(dāng)我...
- 文/花漫 我一把揭開白布狮崩。 她就那樣靜靜地躺著,像睡著了一般鹿寻。 火紅的嫁衣襯著肌膚如雪睦柴。 梳的紋絲不亂的頭發(fā)上,一...
- 文/蒼蘭香墨 我猛地睜開眼蘸炸,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了尖奔?” 一聲冷哼從身側(cè)響起搭儒,我...
- 正文 年R本政府宣布坯苹,位于F島的核電站隆檀,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏粹湃。R本人自食惡果不足惜恐仑,卻給世界環(huán)境...
- 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望为鳄。 院中可真熱鬧裳仆,春花似錦、人聲如沸孤钦。這莊子的主人今日做“春日...
- 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至静袖,卻和暖如春觉鼻,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背勾徽。 一陣腳步聲響...
推薦閱讀更多精彩內(nèi)容
- 參考:第三篇:iOS動畫系列之三:Core Animation。介紹了Core Animation的常用屬性和方法...
- UIView和核心動畫的區(qū)別 核心動畫只能添加到CALayer,UIView沒有辦法使用核心動畫 核心動畫一切都是...
- 每個人的心中都住著兩只狼乌昔,一只善隙疚,一只惡。如果說走向心智成熟的旅程是善磕道,那么與成長背道而馳供屉,迷失在謊言的陷阱里就是...