iOS動畫-定時對UIView進(jìn)行翻轉(zhuǎn)和抖動的方法
更新時間:2017年04月23日 10:33:17 投稿:jingxian
下面小編就為大家?guī)硪黄猧OS動畫-定時對UIView進(jìn)行翻轉(zhuǎn)和抖動的方法。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
(翻轉(zhuǎn))方式一:
[NSTimer scheduledTimerWithTimeInterval:3.f repeats:YES block:^(NSTimer * _Nonnull timer) {
CABasicAnimation* rotationAnimation = [CABasicAnimation animation];;
rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.y"];
rotationAnimation.toValue = [NSNumber numberWithFloat: M_PI * 2.0 ];
rotationAnimation.duration = 1;
// 切換界面保證動畫不停止
rotationAnimation.removedOnCompletion = NO;
rotationAnimation.repeatCount = 1;
[self.bindCardImageView.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];
}];
(翻轉(zhuǎn))方式二(這種方式較好一些):
CABasicAnimation *waitAnimation = [CABasicAnimation animation];
waitAnimation.toValue = [NSNumber numberWithFloat:1.0];
waitAnimation.duration = 3.f;
waitAnimation.beginTime = 3.f;
CABasicAnimation* rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.y"];
rotationAnimation.toValue = [NSNumber numberWithFloat: M_PI * 2.0 ];
rotationAnimation.duration = 1.f;
CAAnimationGroup *group = [CAAnimationGroup animation];
group.duration = 4.f;
group.repeatCount = CGFLOAT_MAX;
group.removedOnCompletion = NO;
[group setAnimations:@[waitAnimation, rotationAnimation]];
[self.bindCardImageView.layer addAnimation:group forKey:@"bindCardImageViewAnimation"];
抖動:
CABasicAnimation* shake = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"]; //設(shè)置抖動幅度 shake.fromValue = [NSNumber numberWithFloat:-0.2]; shake.toValue = [NSNumber numberWithFloat:+0.2]; shake.duration = 0.1; shake.autoreverses = YES; //是否重復(fù) shake.repeatCount = 3; [itemView.iconImageView.layer addAnimation:shake forKey:@"imageView"];
以上這篇iOS動畫-定時對UIView進(jìn)行翻轉(zhuǎn)和抖動的方法就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
iOS動態(tài)調(diào)整UILabel高度的幾種方法
在iOS編程中UILabel是一個常用的控件,下面這篇文章主要給大家介紹了關(guān)于iOS動態(tài)調(diào)整UILabel高度的幾種方法,文中通過示例代碼介紹的非常詳細(xì),需要的朋友可以參考借鑒,下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。2017-12-12
iOS中使用Fastlane實現(xiàn)自動化打包和發(fā)布
Fastlane是一套使用Ruby寫的自動化工具集,用于iOS和Android的自動化打包、發(fā)布等工作,可以節(jié)省大量的時間。下面給大家介紹ios fastlane 自動化打包和發(fā)布的安裝方法,需要的朋友參考下吧2017-05-05
Objective-C中NSNumber與NSDictionary的用法簡介
這篇文章主要介紹了Objective-C中NSNumber與NSDictionary的用法簡介,雖然Objective-C即將不再是iOS的主流開發(fā)語言...well,需要的朋友可以參考下
2015-09-09
iOS AVPlayer切換播放源實現(xiàn)連續(xù)播放和全屏切換的方法
這篇文章主要給大家介紹了關(guān)于iOS中AVPlayer切換播放源實現(xiàn)連續(xù)播放和全屏切換的方法,文中給出了詳細(xì)的示例代碼供大家參考學(xué)習(xí),對大家具有一定的參考學(xué)習(xí)價值,需要的朋友們下面來一起看看吧。
2017-05-05 
