2009-12-31 94 views
2

我有這個我的viewController裏:iPhone搖事件不能正常工作

- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event { 

    if (event.type == UIEventSubtypeMotionShake) { 

     NSLog(@"I have shaked"); 

    } 
} 

這是爲什麼不工作? 編輯:


我做INFACT有這樣的:

- (void) viewWillAppear:(BOOL)animated 
{ 
    [shakeView becomeFirstResponder]; 
    [super viewWillAppear:animated]; 
} 
- (void) viewWillDisappear:(BOOL)animated 
{ 
    [shakeView resignFirstResponder]; 
    [super viewWillDisappear:animated]; 
} 

回答

3

如果UIViewController在應用程序的開始時被加載,我已經看到OS 3.0中有一個奇怪的故障,它不會成爲第一響應者,除非您延遲了相應的消息。嘗試放置

[self performSelector:@selector(becomeFirstResponder) withObject:nil afterDelay:0.3]; 

within -loadView或控制器第一次設置時調用的其他內容。

有可能有一個更優雅的方法來解決這個問題,但這種方法已經爲我工作。

0

的的viewController必須搖中的第一個響應收到此事件。

這可能是它不起作用的原因之一。

+0

我確實有這個 – Jaba 2009-12-31 06:20:06