微信的摇一摇动画效果看起来很棒,这里是类似的摇一摇动画效果,代码示例:
| 代码如下 | 复制代码 |
| #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”,实现的摇一摇动画效果看起来还不错,可以在自己的工程里试一试。
DeepSeek多模态怎么样及保姆级配置教程(codex、claude)实用指南
WSL2+Docker+Ollama本地部署大模型思路和实践指南(Qwen1.8b)实用指南
DeepSeek Harness热门插件盘点:10个实用插件,覆盖多Agent、上下文和多模态实用指南
grep文本搜索与正则表达式完整代码示例实用指南
AI漫剧伪装直男1‑24集无雾版夸克网盘资源免费分享
AI漫剧玉僧入尘1-68集无雾无删版夸克网盘资源免费分享