轉(zhuǎn)場(chǎng)動(dòng)畫
一、CATransition簡(jiǎn)介
- CATransition是CAAnimation的子類,用于做轉(zhuǎn)場(chǎng)動(dòng)畫,能夠?yàn)閷犹峁┮瞥銎聊缓鸵迫肫聊坏膭?dòng)畫效果。iOS比Mac OS X的轉(zhuǎn)場(chǎng)動(dòng)畫效果少一點(diǎn)
- UINavigationController就是通過CATransition實(shí)現(xiàn)了將控制器的視圖推入屏幕的動(dòng)畫效果
- 動(dòng)畫屬性:
- type:動(dòng)畫過渡類型
- subtype:動(dòng)畫過渡方向
- startProgress:動(dòng)畫起點(diǎn)(在整體動(dòng)畫的百分比)
- endProgress:動(dòng)畫終點(diǎn)(在整體動(dòng)畫的百分比)
二、轉(zhuǎn)場(chǎng)動(dòng)畫的過渡效果
見圖
使用UIView動(dòng)畫函數(shù)實(shí)現(xiàn)轉(zhuǎn)場(chǎng)動(dòng)畫——單視圖
+ (void)transitionWithView:(UIView *)view duration:(NSTimeInterval)duration options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion;
- 參數(shù)說明:
- duration:動(dòng)畫的持續(xù)時(shí)間
- view:需要進(jìn)行轉(zhuǎn)場(chǎng)動(dòng)畫的視圖
- options:轉(zhuǎn)場(chǎng)動(dòng)畫的類型
- animations:將改變視圖屬性的代碼放在這個(gè)block中
- completion:動(dòng)畫結(jié)束后,會(huì)自動(dòng)調(diào)用這個(gè)block
使用UIView動(dòng)畫函數(shù)實(shí)現(xiàn)轉(zhuǎn)場(chǎng)動(dòng)畫——雙視圖
+ (void)transitionFromView:(UIView *)fromView toView:(UIView *)toView duration:(NSTimeInterval)duration options:(UIViewAnimationOptions)options completion:(void (^)(BOOL finished))completion;
- 參數(shù)說明:
- duration:動(dòng)畫的持續(xù)時(shí)間
- options:轉(zhuǎn)場(chǎng)動(dòng)畫的類型
- animations:將改變視圖屬性的代碼放在這個(gè)block中
- completion:動(dòng)畫結(jié)束后,會(huì)自動(dòng)調(diào)用這個(gè)block
三、CADisplayLink
CADisplayLink是一種以屏幕刷新頻率觸發(fā)的時(shí)鐘機(jī)制,
每秒鐘執(zhí)行大約60次左右CADisplayLink是一個(gè)
計(jì)時(shí)器,可以使繪圖代碼與視圖的刷新頻率保持同步,而NSTimer無法確保計(jì)時(shí)器實(shí)際被觸發(fā)的準(zhǔn)確時(shí)間-
使用方法:
- 定義CADisplayLink并制定觸發(fā)調(diào)用方法
- 將顯示鏈接添加到主運(yùn)行循環(huán)隊(duì)列
示例:
- (CADisplayLink *)link
{
if (_link == nil) {
_link = [CADisplayLink displayLinkWithTarget:self selector:@selector(rotationChange)];
[_link addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSDefaultRunLoopMode];
}
return _link;
}