iOS動畫-定時對UIView進行翻轉(zhuǎn)和抖動的方法
更新時間:2017年04月23日 10:33:17 投稿:jingxian
下面小編就為大家?guī)硪黄猧OS動畫-定時對UIView進行翻轉(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進行翻轉(zhuǎn)和抖動的方法就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
iOS應(yīng)用程序之間的幾種跳轉(zhuǎn)情況詳解
這篇文章給大家詳細(xì)介紹了iOS應(yīng)用程序之間跳轉(zhuǎn)的幾種情況,包括跳轉(zhuǎn)到另一個程序的主界面、跳轉(zhuǎn)到另一個程序的指定界面以及如何從目標(biāo)程序的非主頁界面回到當(dāng)前(跳轉(zhuǎn)前)程序呢?有需要的朋友們可以下面來一起看看。2016-09-09Xcode中iOS應(yīng)用開發(fā)的一般項目目錄結(jié)構(gòu)和流程簡介
這篇文章主要介紹了Xcode中iOS應(yīng)用開發(fā)的一般項目目錄結(jié)構(gòu)和流程簡介,包括項目所需的一些平臺路徑如模擬器路徑等的介紹,需要的朋友可以參考下2016-02-02深入學(xué)習(xí)iOS7自定義導(dǎo)航轉(zhuǎn)場動畫
這篇文章主要為大家詳細(xì)介紹了iOS7自定義導(dǎo)航轉(zhuǎn)場動畫的相關(guān)資料,感興趣的小伙伴們可以參考一下2016-02-02iOS開發(fā)中一些手寫控件及其相關(guān)屬性的使用
這篇文章主要介紹了iOS開發(fā)中一些手寫控件及其相關(guān)屬性的使用,代碼基于傳統(tǒng)的Objective-C,需要的朋友可以參考下2015-12-12