最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
苹果开发之iOS 摇一摇动画
时间:2022-06-25 23:36:40 编辑:袖梨 来源:一聚教程网
微信的摇一摇动画效果看起来很棒,这里是类似的摇一摇动画效果,代码示例:
| 代码如下 | 复制代码 |
| #pragma mark - 摇一摇 - (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event { if (motion == UIEventSubtypeMotionShake) { AudioServicesPlaySystemSound(kSystemSoundID_Vibrate); //震动效果 [self shakeView:phoneImgView]; //这里的phoneImgView是需要摇动效果的图片控件 } } #pragma mark - 动画 -(void)shakeView:(UIView*)viewToShake { CGFloat t = 14.0; CGAffineTransform translateRight = CGAffineTransformTranslate(CGAffineTransformIdentity, t, 0.0); CGAffineTransform translateLeft = CGAffineTransformTranslate(CGAffineTransformIdentity, -t, 0.0); viewToShake.transform = translateLeft; [UIView animateWithDuration:0.08 delay:0.0 options:UIViewAnimationOptionAutoreverse|UIViewAnimationOptionRepeat animations:^{ [UIView setAnimationRepeatCount:5.0]; viewToShake.transform = translateRight; } completion:^(BOOL finished){ if(finished){ [UIView animateWithDuration:0.08 delay:0.0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{ viewToShake.transform =CGAffineTransformIdentity; } completion:NULL]; } }]; } | |
注:需要震动效果时,要导入AudioToolbox.framework,然后导入头文件”AudioToolbox/AudioToolbox.h”,实现的摇一摇动画效果看起来还不错,可以在自己的工程里试一试。
相关文章
- mcjs网页版即点即玩-mcjs极速秒玩入口 10-23
- 超星学习通网页版登录-超星学习通官网入口 10-23
- poki免费游戏大全-poki免费游戏在线畅玩入口 10-23
- mc.js官方在线入口 10-23
- 海角haijiao社区2025全新网址一键直达-海角社区最新官方入口地址 10-23
- 王者荣耀世界体力上限与恢复方法详解 王者荣耀世界体力机制全面解析 10-20