"MindManager"學習iOS系列之"CAAnimation-核心動畫"詳解,思惟導圖內展現了CAAnimation-核心動畫的大多數基本功能和知識,每一個part都有代碼講解,展現出CAAnimation-核心動畫的清晰輪廓,編者提供了"JPG"、"SWF"、"PDF"、"Word"、"Mmap"格式的源文件供給使用。注意:JPG格式僅爲圖片總覽,SWF格式使用微軟IE瀏覽器瀏覽便可,Word以全文本形式給出框架圖,Mmap格式體會MindManager的魅力。To Be Continue,CAAnimation-核心動畫的新知識,新想法,新思路慢慢更新,歡迎提出寶貴建議。瀏覽器
-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-框架
iAronTalk Blog opens.函數
The study certainly is not the life complete. But, since continually life part of - studies also is unable to conquer, what but also can make?學習
-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-動畫
各類類型文件的下載地址:http://pan.baidu.com/s/1pJnBtLhspa
在iOS中隨處均可以看到絢麗的動畫效果,實現這些動畫的過程並不複雜,今天將帶你們一窺iOS動畫全貌。在這裏你能夠看到iOS中如何使用圖層精簡非交互式繪圖,如何經過核心動畫建立基礎動畫、關鍵幀動畫、動畫組、轉場動畫,如何經過UIView的裝飾方法對這些動畫操做進行簡化等。在今天的文章裏您能夠看到動畫操做在iOS中是如何簡單和高效,不少原來想作可是苦於沒有思路的動畫在iOS中將變得愈加簡單。代理
每一個小知識點中都有相應的demo說明。orm
-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-對象
後續會將集成導出的word內容展現在後面,系統自動集成,與做者原用意略有差別,使用SWF"、"PDF"、"Mmap"格式最佳。 blog
Core Animation CAAnimation (抽象類)
1 繼承結構CAAnimation
1.1 CATransition
1.2 CAAnimationGroup
1.3 CAPropertyAnimation 抽象類
1.3.1 CABasicAnimation
1.3.2 CAKeyFrameAnimation
2 何爲CAAnimation
2.1 CAAnimation性格分析
2.2 屬性
參閱: 協議屬性
·removedOnCompletion:默認爲YES,表明動畫執行完畢後就從圖層上移除,圖形會恢復到 動畫執行前的狀態。
若是想讓圖層保持顯示動畫執行後的狀態,那就設置爲NO,不過還要設置fillMode爲 kCAFillModeForwards
·timingFunction:速度控制函數,控制動畫運行的節奏
·delegate:動畫代理
·fillMode屬性 (要想fillMode有效,最好設置removeOnCompletion = NO)
·kCAFillModeRemoved 默認值,動畫開始前和動畫結束後,動畫對layer都沒有影
響,動畫結束後,layer會恢復到動畫開始前的狀態
·kCAFillModeForwards 當動畫結束後,layer會保持動畫最後的顯示狀態
·kCAFillModeBackwards 在動畫開始前,只須要將動畫加入了一個layer, layer便
當即進入動畫的初始狀態並等待動畫的開始
·kCAFillModeBoth 上面兩個的合成,動畫加入後開始前,layer便處於動畫初始狀
態,動畫結束後layer保持動畫最後的狀態
·速度控制函數(CAMediaTimingFunction)
·kCAMediaTimingFunctionLinear(線性):勻速,給你一個相對靜態的感受
·kCAMediaTimingFunctionEaseIn(漸進):動畫緩慢進入,而後加速離開
·kCAMediaTimingFunctionEaseOut(漸出):動畫全速進入,而後減速的到
達目的地
·kCAMediaTimingFunctionEaseInEaseOut(漸進漸出):動畫緩慢的進
入,中間加速,而後減速的到達目的地。這個是默認的動畫行爲。
3 CAMediaTiming(協議)
3.1 協議屬性
·duration:動畫的持續時間
·repeatCount:重複次數,無限循環能夠設置HUGE_VALF或者MAXFLOAT
·repeatDuration:重複時間
·fillMode:決定當前對象在非active時間段的行爲。好比動畫開始以前或者動畫結束以後
·CACurrentMediaTime()爲圖層的當前時間
·beginTime:能夠用來設置動畫延遲執行時間,若想延遲2s,就設置爲 CACurrentMediaTime()+2。
4 Main Topic
5 進入CCAnimation的世界
5.1 CATransition
1) CATransition是CAAnimation的子類,用於作轉場動畫,可以爲層提供移出
屏幕和移入屏幕的動畫效果。iOS比Mac OS X的轉場動畫效果少一點
2) UINavigationController就是經過CATransition實現了將控制器的視圖推入屏
幕的動畫效果.
3) 動畫屬性:
·type:動畫過渡類型
·subtype:動畫過渡方向
·startProgress:動畫起點(在總體動畫的百分比)
·endProgress:動畫終點(在總體動畫的百分比)
4) type:動畫過渡類型,如圖:
5)
5.1.1 .h
// ViewController.h
// CAAnimation03
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
{
UIView *_superView;
}
@end
5.1.2 .m
// ViewController.m
// CAAnimation03
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// 核心動畫
// 1.建立視圖
_superView = [[UIView alloc] initWithFrame:self.view.bounds];
_superView.backgroundColor = [UIColor whiteColor];
[self.view addSubview:_superView];
// 01 建立視圖1
UIView *view1 = [[UIView alloc] initWithFrame:self.view.bounds];
view1.backgroundColor = [UIColor orangeColor];
[_superView addSubview:view1];
// 02 建立視圖2
UIView *view2 = [[UIView alloc] initWithFrame:self.view.bounds];
view2.backgroundColor = [UIColor redColor];
[_superView addSubview:view2];
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
// 1.建立動畫對象
CATransition *transition = [CATransition animation];
transition.duration = .35;
// 設置加速方式
transition.timingFunction = [CAMediaTimingFunction functionWithName:@"default"];
// 設置動畫樣式
//·type:動畫過渡類型
//·subtype:動畫過渡方向
transition.type = @"cameraIrisHollowOpen";
transition.subtype = kCATransitionFromRight;
[_superView.layer addAnimation:transition forKey:@"transition"];
// 切換視圖
[_superView exchangeSubviewAtIndex:0 withSubviewAtIndex:1];
}
@end
5.2 CABasicAnimation
5.2.1 .h
// ViewController.h
// CABasicAnimation04
//
//
本例使用storyboard建立,適合有點基礎的學習。
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
{
UIView *_subView;
// 暫停的事件
CFTimeInterval _timeInterval;
// 當前暫停時刻
CFTimeInterval _newStopTime;
}
- (IBAction)startAction:(id)sender;
- (IBAction)stopAction:(id)sender;
- (IBAction)remveAction:(id)sender;
@end
5.2.2 .m
// ViewController.m
// CABasicAnimation04
#import "ViewController.h"
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
_subView = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
_subView.backgroundColor = [UIColor redColor];
[self.view addSubview:_subView];
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
// 使用CABasicAnimation設置動畫
CABasicAnimation*basic=[CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
// 設置開始位置
basic.fromValue = @(0);
basic.toValue = @(M_PI * 2);
// 設置動畫執行完成的一個狀態
basic.fillMode = kCAFillModeForwards;
basic.removedOnCompletion = NO;
// 配置動畫事件
basic.duration = 2;
basic.repeatCount = 100;
// 還原的時候也有動畫效果
basic.autoreverses = NO;
[_subView.layer addAnimation:basic forKey:@"basicKey"];
}
- (IBAction)startAction:(id)sender {
// 恢復動畫
// 1.恢復速度
_subView.layer.speed = 1.0;
// 2.設置延遲實行事件
_timeInterval += CACurrentMediaTime() - _newStopTime;
_subView.layer.beginTime = _timeInterval;
NSLog(@"%f",_subView.layer.timeOffset);
// 3.取消以前的位置設置
_subView.layer.timeOffset = 0;
}
- (IBAction)stopAction:(id)sender {
// 設置layer的移動速度爲0,至關於中止了
_subView.layer.speed = 0.0;
// 設置layer位置,是相對於時間的位置
_newStopTime = CACurrentMediaTime();
_subView.layer.timeOffset = _newStopTime;
}
- (IBAction)remveAction:(id)sender {
[_subView.layer removeAnimationForKey:@"basicKey"];
}
@end
5.3 CAKeyFrameAnimation
5.4 CAAnimationGroup
未完待續。
-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
因爲編者水平有限,不妥之處在所不免,懇請各個大牛批評指正,提出寶貴建議。