IOS开发之——动画-图标抖动(97)
生活随笔
收集整理的這篇文章主要介紹了
IOS开发之——动画-图标抖动(97)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
一 概述
- 模仿刪除應用時的圖標抖動
- 頁面上添加圖片,勾選屬性User Interaction Enabled,給圖片設置長按事件,并執行抖動動畫
- 圖標抖動時,先往左旋轉5度,再向右旋轉5度,再向左旋轉5度恢復原位置,再重新開始
二 過程
2.1 Main.storyboard中添加動畫,并設置User Interaction Enabled
User Interaction Enabled2.2 定義旋轉角度
#define angle2radian(x) ((x)/180.0*M_PI)2.3 長按事件
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添加長按事件
[_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 效果圖
總結
以上是生活随笔為你收集整理的IOS开发之——动画-图标抖动(97)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 为什么王者荣耀总是服务器中断,王者荣耀服
- 下一篇: Snagit 2020 Windows和