核心动画--基本动画
生活随笔
收集整理的這篇文章主要介紹了
核心动画--基本动画
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
#pragma mark 動(dòng)畫暫停- (void)pauseAnimation{// 1. 取出當(dāng)前的動(dòng)畫的時(shí)間點(diǎn),就是要暫停的時(shí)間點(diǎn)
CFTimeInterval pauseTime = [self.myView.layer convertTime:CACurrentMediaTime() fromLayer:nil];// 2. 設(shè)置動(dòng)畫的時(shí)間偏移量,指定時(shí)間偏移量的目的是讓動(dòng)畫定格在該時(shí)間點(diǎn)
[self.myView.layer setTimeOffset:pauseTime];// 3. 將動(dòng)畫的運(yùn)行速度設(shè)置為0,動(dòng)畫默認(rèn)的運(yùn)行速度是1.0
[self.myView.layer setSpeed:0.0];}#pragma mark 恢復(fù)動(dòng)畫- (void)resumeAnimation{// 1. 將動(dòng)畫的時(shí)間偏移量作為暫停時(shí)的時(shí)間點(diǎn)
CFTimeInterval pauseTime = self.myView.layer.timeOffset;// 2. 根據(jù)媒體時(shí)間計(jì)算出準(zhǔn)確的啟動(dòng)動(dòng)畫時(shí)間,對(duì)之前暫停動(dòng)畫的時(shí)間進(jìn)行修正
CFTimeInterval beginTime = CACurrentMediaTime() - pauseTime;// 3. 要把偏移時(shí)間清零
[self.myView.layer setTimeOffset:0.0];// 4. 設(shè)置圖層的開始動(dòng)畫時(shí)間
[self.myView.layer setBeginTime:beginTime];[self.myView.layer setSpeed:1.0];}注意:
// 對(duì)于循環(huán)播放的動(dòng)畫效果,一定要將removedOnCompletion設(shè)置為NO,否則無法恢復(fù)動(dòng)畫
[anim setRemovedOnCompletion:NO];#pragma mark 旋轉(zhuǎn)動(dòng)畫- (void)rotationAnimation{// 1. 實(shí)例化基本動(dòng)畫// 默認(rèn)按照z軸旋轉(zhuǎn)
CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];[self.myView.layer setAnchorPoint:CGPointMake(0, 0)];// 2. 設(shè)置動(dòng)畫屬性// 不停的旋轉(zhuǎn)// 1) 旋轉(zhuǎn)一周
[anim setToValue:@(2 * M_PI)];// 2) 不停的旋轉(zhuǎn) - 動(dòng)畫循環(huán)播放// HUGE_VALF 是一個(gè)非常大得浮點(diǎn)數(shù),指定此數(shù)值可以認(rèn)為動(dòng)畫無限循環(huán)// MAXFLOAT
[anim setRepeatCount:HUGE_VALF];[anim setDuration:0.5f];// 3) 動(dòng)畫完成時(shí)刪除// 對(duì)于循環(huán)播放的動(dòng)畫效果,一定要將removedOnCompletion設(shè)置為NO,否則無法恢復(fù)動(dòng)畫
[anim setRemovedOnCompletion:NO];// 3. 添加動(dòng)畫// key可以隨便指定,用于判斷圖層中是否存在該動(dòng)畫
[self.myView.layer addAnimation:anim forKey:@"rotationAnim"];}
?
轉(zhuǎn)載于:https://www.cnblogs.com/yyh123/p/3346439.html
總結(jié)
以上是生活随笔為你收集整理的核心动画--基本动画的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 关于VC++6.0中getline函数的
- 下一篇: 移除VS解决方案中的TFS版本控制