我正在使用此代码进行抖动检测,并且在大多数情况下它工作正常:
- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event {
if (event.type == UIEventSubtypeMotionShake) {
if ( event.subtype == UIEventSubtypeMotionShake )
{
NSLog (@"Shake Called");
}
}
我相信要使它起作用,我还需要使用这些,我有:
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self becomeFirstResponder];
}
- (void)viewDidDisappear:(BOOL)animated {
[self resignFirstResponder];
[super viewDidDisappear:animated];
}
这一切都很好,motionEnded
每次我摇晃时都会调用它,直到我点击webView
我程序中的链接。我可以在视图中上下滚动并且摇动仍然有效,但是一旦视图加载新页面,motionEnded
当我摇动时停止被调用。这发生在模拟器和真实设备(iPhone 3G、iOS4)上。根据我有限的理解,我相信这与急救人员有关,但我可能错了!