IOS开发之——动画-图标抖动(97)
生活随笔
收集整理的這篇文章主要介紹了
IOS开发之——动画-图标抖动(97)
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
一 概述
- 模仿刪除應(yīng)用時(shí)的圖標(biāo)抖動(dòng)
- 頁(yè)面上添加圖片,勾選屬性User Interaction Enabled,給圖片設(shè)置長(zhǎng)按事件,并執(zhí)行抖動(dòng)動(dòng)畫
- 圖標(biāo)抖動(dòng)時(shí),先往左旋轉(zhuǎn)5度,再向右旋轉(zhuǎn)5度,再向左旋轉(zhuǎn)5度恢復(fù)原位置,再重新開始
二 過(guò)程
2.1 Main.storyboard中添加動(dòng)畫,并設(shè)置User Interaction Enabled
User Interaction Enabled2.2 定義旋轉(zhuǎn)角度
#define angle2radian(x) ((x)/180.0*M_PI)2.3 長(zhǎng)按事件
UILongPressGestureRecognizer *longPress=[[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(longPress:)];-(void)longPress:(UILongPressGestureRecognizer *)longPress {if (longPress.state==UIGestureRecognizerStateBegan) {CAKeyframeAnimation *anim=[CAKeyframeAnimation animation];anim.keyPath=@"transform.rotation";anim.values=@[@(angle2radian(-5)),@(angle2radian(5)),@(angle2radian(-5))];anim.repeatCount=MAXFLOAT;anim.duration=0.5;[_imageView.layer addAnimation:anim forKey:nil];} }2.4 ImageView添加長(zhǎng)按事件
[_imageView addGestureRecognizer:longPress];2.5 代碼
- (void)viewDidLoad {[super viewDidLoad];UILongPressGestureRecognizer *longPress=[[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(longPress:)];[_imageView addGestureRecognizer:longPress];} -(void)longPress:(UILongPressGestureRecognizer *)longPress {if (longPress.state==UIGestureRecognizerStateBegan) {CAKeyframeAnimation *anim=[CAKeyframeAnimation animation];anim.keyPath=@"transform.rotation";anim.values=@[@(angle2radian(-5)),@(angle2radian(5)),@(angle2radian(-5))];anim.repeatCount=MAXFLOAT;anim.duration=0.5;[_imageView.layer addAnimation:anim forKey:nil];} }2.6 效果圖
總結(jié)
以上是生活随笔為你收集整理的IOS开发之——动画-图标抖动(97)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 为什么王者荣耀总是服务器中断,王者荣耀服
- 下一篇: Snagit 2020 Windows和