iOS删除应用时摇晃效果的实现
在 iOS 中,长按桌面上的应用,应用将进入删除、移动状态,所有的应用图标开始摇晃,好像在说:“别删我,别删我!”很形象,也很有趣。
目前在公司做一个 iPad 上的软件,它有本地文件预览功能(文件的第一页做为文件的图标),及一些诸如删除之类的操作。在删除操作上我想实现像删除应用一样的摇晃效果。
ShowImageViewController.h
#import <UIKit/UIKit.h> @protocol ShowImageDelegate <NSObject> - (void) renovateTableView; @end @class Singleton; @interface ShowImageViewController : UIViewController @property (nonatomic, retain) UIScrollView *scrollView; @property(nonatomic,assign) id< ShowImageDelegate > showdelegate; @property (nonatomic, assign) NSInteger imageSelect; @property (nonatomic, retain) NSArray *imageOneDayPath; @end @interface UIImageView (MyExtension) - (void)wobble:(BOOL)wobble; @end
#import "ShowImageViewController.h"
@implementation UIImageView (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 = CGAffineTransformMakeRotation(D_TO_R(2)); } completions:nil]; } else{ [UIView animateWithDuration:0.25 delay:0.0 options:UIViewAnimationOptionAllowUserInteraction|UIViewAnimationOptionBeginFromCurrentState|UIViewAnimationOptionCurveEaseOut animations:^{ self.transform = CGAffineTransformIdentity; } completions:nil]; } }
@end
@interfaceShowImageViewController ()
@end
@implementation ShowImageViewController
@synthesize showdelegate = _showdelegate;
@synthesize imageSelect = _imageSelect, imageOneDayPath = _imageOneDayPath;
这样,在需要的地方调用
[self wobble:YES]; //如果改成UIView 则调用就是ios删除应用时的所有图标都在晃动的效果
就好了,当然别忘了包含头文件
注解:主要方法是wobble ,你可以在任何你想要晃动的控件(如:UIImageView等)加个类别写入wobble方法,然后再调用就可以的。