iOS開發(fā)動(dòng)畫(Animation)圖片360度不停旋轉(zhuǎn)

iOS開發(fā)動(dòng)畫(Animation)圖片360度不停旋轉(zhuǎn)

iOS開發(fā)動(dòng)畫(Animation)圖片360度不停旋轉(zhuǎn)

最開始的想法是讓旋轉(zhuǎn)的弧度從0到2 * M_PI, ?讓動(dòng)畫不停的repeat,實(shí)驗(yàn)了一下,沒(méi)有任何效果,系統(tǒng)動(dòng)畫的時(shí)候看到0與2 *M_PI是同一起一始點(diǎn),所以沒(méi)有效果。

后來(lái)想到一種辦法,就是一個(gè)變量不斷的累加變大,這樣影響弧度也隨著變化,就達(dá)到了圓周運(yùn)動(dòng)的效果。

直接上代碼:

-(void)?startAnimation

{

[UIView?beginAnimations:nil?context:nil];

[UIView?setAnimationDuration:0.01];

[UIView?setAnimationDelegate:self];

[UIView?setAnimationDidStopSelector:@selector(endAnimation)];

imageView.transform?=?CGAffineTransformMakeRotation(angle?*?(M_PI?/?180.0f));

[UIView?commitAnimations];

}

-(void)endAnimation

{

angle?+=?10;

[self?startAnimation];

}

當(dāng)然你可以用block的方式寫也是一樣的。

-?(void)startAnimation

{

CGAffineTransform?endAngle?=?CGAffineTransformMakeRotation(imageviewAngle?*?(M_PI?/?180.0f));

[UIView?animateWithDuration:0.01?delay:0?options:UIViewAnimationOptionCurveLinear?animations:^{

imageView.transform?=?endAngle;

}?completion:^(BOOLfinished)?{

angle?+=?10;?[self?startAnimation];

}];

}

PS:其中angle是double類型。

這下就可以360度旋轉(zhuǎn)了。

還有一種方法:

CABasicAnimation*?rotationAnimation;

rotationAnimation?=?[CABasicAnimation?animationWithKeyPath:@"transform.rotation.z"];

rotationAnimation.toValue?=?[NSNumber?numberWithFloat:?M_PI?*?2.0?];

rotationAnimation.duration?=?duration;

rotationAnimation.cumulative?=?YES;

rotationAnimation.repeatCount?=?repeat;

[_loadingView.layer?addAnimation:rotationAnimation?forKey:@"rotationAnimation"];

reference:https://github.com/jonasschnelli/UIView-i7Rotate360

0

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容