我有一个 ViewController 可以完美地与触发动作的按钮配合使用。我想用一个摇动事件替换按钮,所以我用谷歌搜索它并创建了一个从 UIView 继承的 ShakeDetector 类
我的实现如下:
@implementation ShakeDetector
- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
}
- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
if (motion == UIEventSubtypeMotionShake )
{
// User was shaking the device. Post a notification named "shake".
//[[NSNotificationCenter defaultCenter] postNotificationName:@"spin" object:self];
NSLog(@"sss");
}
}
- (void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
}
@end
但我不能让它工作......有什么帮助吗?
谢谢