一个微小的分类,包含一个方法,用于检测到晃动时发送 NSNotification :)
将 DHCShakeNotifier
的内容添加到您的项目中
克隆/下载仓库并快速查看示例。
导入 DHCShakeNotifier
#import "UIWindow+DHCShakeRecognizer.h"
通过添加 NSNotification 观察者来监听晃动通知
@implementation YourObject
...
-(id)init{
if (self==[super init]) {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(methodThatIsCalledAfterShake) name:@"CONJUShakeNotification" object:nil];
}
return self;
}
...
-(void)methodThatIsCalledAfterShake{
NSLog(@"\"I have just been shaken\" - A martini after being ordered by James Bond");
}
...
-(void)dealloc{
[[NSNotificationCenter defaultCenter] removeObserver:self name:DHCSHakeNotifName object:nil];
}
...
@end