【问题标题】:Shake recognition not working on iOS 4, does work on iOS 5摇晃识别在 iOS 4 上不工作,在 iOS 5 上工作
【发布时间】:2011-12-10 17:55:47
【问题描述】:

我在我的应用中集成了震动识别功能。我已将它放在我的 appdelegate 中,以便能够在整个应用程序中使用它。它在 iOS 5 上运行良好,但在 iOS 4 上却不起作用。

我在 appdelegate.m 中使用以下代码:

- (void)applicationDidBecomeActive:(UIApplication *)application {
   [self becomeFirstResponder];
   ....
}

-(BOOL)canBecomeFirstResponder {
   return YES;
}

- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event {
    NSLog(@"motionBegan");
}

-(void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event{
    NSLog(@"motionEnded");
}

如果我在 iOS5 模拟器中运行它并激活摇动手势,我会收到 NSLog 消息。如果我在 iOS 4.3 模拟器中运行它,它就不起作用。真实设备也是如此。

【问题讨论】:

  • 遇到同样的问题,你解决了吗

标签: ios xcode shake


【解决方案1】:

我有同样的问题。试试

- (void)viewDidAppear:(BOOL)animated {
   [self becomeFirstResponder];
}

而不是

- (void)applicationDidBecomeActive:(UIApplication *)application {
   [self becomeFirstResponder];
   ....
}

Event Handling Guide: Motion Events。这对我有用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-03-28
    • 1970-01-01
    • 2013-03-03
    • 2014-06-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-19
    相关资源
    最近更新 更多