我已經在iPad和iPad模擬器上對此進行了測試,並且在一次成功搖晃之後,motionBegan方法從不會被調用。以下是我的程序片段。搖動不再起作用UIAlertview
- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
if(event.type == UIEventSubtypeMotionShake)
{
NSLog(@"Shake event occurred.");
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"Information" message:@"Some message here" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil];
alert.tag = shakeTag;
[alert show];
}
}
- (BOOL)canBecomeFirstResponder
{
return YES;
}
-(void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:NO];
[self becomeFirstResponder];
}
-(void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:NO];
}
-(void)viewDidDisappear:(BOOL)animated {
[self resignFirstResponder];
[super viewDidDisappear:NO];
}
防止motionBegan方法再次發生的是什麼?我希望UIAlertView能夠在第一次搖動時精確顯示一次,並在隨後的所有搖動中被解散。我有一種預感,第一響應者仍然依附於UIAlertView,它阻止了再次調用motionBegan方法。
更新:在我相應的UIView中,有一個UIActionSheet被創建。這是在我的UIView中調用和實現的),並且在屏幕上顯示UIActionSheet的同時觸發motionBegan方法(它位於我的UIViewController中),這是motionBegan方法不再能夠被調用的問題。
之後,UIAlertView從任何按鈕選擇中消除,motionBegan方法不再被調用,但UIActionSheet工作得很好。在UIView中沒有firstResponder賦值,並且UIViewController中只存在「canBecomeFirstResponder」。有任何想法嗎?
我複製並粘貼了你的代碼,並且它在iPad模擬器上反覆工作(我唯一拿出的是alert.tag = shakeTag行)。 – rdelmar 2013-03-12 00:58:59
@rdelmar它在iPAD模擬器上不適用於我。硬件震動手勢不再調用motionBegan,因爲只有一行輸出:「NSLog(@」震動事件發生。「);」我有以下方法來處理特定的警報標籤,「 - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex」 – David 2013-03-12 01:08:43
嗯,我不知道爲什麼你的不工作。我添加了標籤和提醒委託方法,對我來說它仍然可以正常工作。 – rdelmar 2013-03-12 01:58:04