在 iOS 中,长按桌面上的应用,应用将进入删除、移动状态,所有的应用图标开始摇晃,好像在说:“别删我,别删我!”很形象,也很有趣。
目前在公司做一个 iPad 上的软件,它有本地文件预览功能(文件的第一页做为文件的图标),及一些诸如删除之类的操作。在删除操作上我想实现像删除应用一样的摇晃效果。
新建 UIMyExtension.m 文件(包括 .h ):
@interface UIView (MyExtension)
- (void)wobble:(BOOL)wobble
{
if (wobble){
self.transform = CGAffineTransformMakeRotation(D_TO_R(-2));
[UIView animationWithDuration:0.12
delay:0.0
options:UIViewAnimationOptionRepeat|UIViewAnimationOptionAutoreverse|UIViewAnimationOptionAllowUserInteraction|UIViewAnimationOptionCurveLinear
animations:^{
self.transform = CGAffineTransformMakeRotati