【问题标题】:Couldn't detect device's shakes无法检测到设备的震动
【发布时间】:2011-07-17 23:41:28
【问题描述】:

我正在尝试检测设备(iPhone/iPod Touch)何时抖动,我已经完成的(在我的 viewController.m 中)是:

- (BOOL) canBecomeFirstResponder{
return YES;
}

.

- (void) motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event{
if (motion == UIEventSubtypeMotionShake){
NSLog(@"Motion detected");
}
}

我已将此行添加到 viewDidLoad :

BOOL ret = [self becomeFirstResponder];

然后,我构建并运行应用程序,并尝试摇动设备但没有任何反应!.. 我开始解决问题,通过使用断点,我检测到从 [self becomeFirstResponder] 返回的“ret”值是“不”。 并且不知道是什么问题。有什么帮助吗?

Info : using Xcode 4, and iOS 4.3

提前致谢。

【问题讨论】:

    标签: cocoa-touch ios accelerometer shake first-responder


    【解决方案1】:

    你看过Shaking-Motion Events吗?

    【讨论】:

    • 是的,这就是我真正所做的。但还是同样的问题:(
    【解决方案2】:

    我确实找到了解决方案..

    [self becomeFirstResponder];
    

    应该只在 viewDidAppear: 中实现,因为我在 viewWillAppear: 和 viewDidLoad 中尝试过,但在这两种方法中都不起作用。

    谢谢

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-22
      • 2019-08-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多