![](/img/trans.png)
[英]CLLocationManager callbacks (locationManager:didUpdateToLocation:fromLocation and locationManager:didFailWithError:) never called
[英]motion callbacks never called
我正在嘗試進行一次搖動事件。 我嘗試過:1) 如何檢測有人搖動iPhone的時間? (肯德爾(Kendall)和伊蘭(Eran)的帖子)2) motionBegan:無效,但nothig有所幫助。 My View成為第一響應者,但從未調用motionBegan / motionEnded。 是否有一些必須完成的additiol設置,或者我錯過了somethig? 我的iOS SDK是4.3。
我有一類UIView:
#import "ShakeView.h"
@implementation ShakeView
- (BOOL)canBecomeFirstResponder {
return YES;
}
- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event {
NSLog (@"123");
if ( event.subtype == UIEventSubtypeMotionShake ) {
NSLog(@"Shake!");
}
if ([super respondsToSelector:@selector(motionEnded:withEvent:)]) {
[super motionEnded:motion withEvent:event];
}
}
@end
在我的ViewController的xib類中,ShakeView是。 我的ViewController推送了:
Wheel *secondViewController = [[Wheel alloc] initWithNibName:@"Wheel" bundle:nil];
[self.navigationController pushViewController:secondViewController animated:YES];
[secondViewController release];
在我的ViewController中:
- (void) viewDidAppear:(BOOL)animated
{
[self.view becomeFirstResponder];
[super viewWillAppear:animated];
NSLog(@"%d", [self.view isFirstResponder]);
}
- (void) viewWillDisappear:(BOOL)animated
{
[self.view resignFirstResponder];
[super viewWillDisappear:animated];
}
它記錄為“ 1”,因此它是第一響應者。 但這沒有其他記錄。
我花了半天的時間在這幾行代碼上,沒有更多的想法了。 有人知道如何解決嗎? 謝謝。
這對幫助SentineL來說為時已晚,但是我遇到了同樣的問題,我喜歡他的問題,因為很明顯,他在應用程序委托的didFinishLaunching
已經安裝了所有相關代碼-除了一條關鍵代碼:
[self.window makeKeyAndVisible];
這很難調試,因為即使沒有此行,其他所有內容也都可以。 您的手勢將起作用,控件將響應,您將能夠使視圖成為第一響應者(如SentineL選中)-但是子類化的窗口或視圖或視圖控制器將永遠不會收到運動事件。
這對我來說沒有意義。 為什么makeKeyAndVisible
會影響加速度計makeKeyAndVisible
影響手勢? 希望一些更有經驗的用戶可以回答。
PS:如果使用此代碼作為示例,我建議您省略條件super respondsToSelector
。 當然,它會響應選擇器。 您要覆蓋它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.