微信的摇一摇动画效果看起来很棒,这里是类似的摇一摇动画效果,代码示例:
| 代码如下 | 复制代码 |
| #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”,实现的摇一摇动画效果看起来还不错,可以在自己的工程里试一试。
deepin20怎么新增字体? deepin20安装字体的教程
Linux如何给文件权限? linux给文件添加可执行权限的技巧
deepin20桌面图标样式怎么修改? deepin更换图标主题的技巧
virtualbox打不开虚拟机怎么办? linux无法访问virtualbox的解决办法
deepin怎么注销系统? deepin系统注销与切换用户的方法
Manjaro linux怎么调鼠标速度? Manjaro鼠标设置光标速度的技巧