摇动识别在iOS 4上不起作用,在iOS 5上可以工作 [英] Shake recognition not working on iOS 4, does work on iOS 5

查看:136
本文介绍了摇动识别在iOS 4上不起作用,在iOS 5上可以工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I've integrated a shake recognition in my app. I've put it in my appdelegate to be able to use it throughout the app. It works great on iOS 5, but on iOS 4 it doesn't work.

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

I'm using the following code in my 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模拟器中运行它,它将无法正常工作.与真实设备相同.

If I run this in the iOS5 simulator and activate the shake gesture I get the NSLog messages. If I run it in the iOS 4.3 simulator it doesn't work. Same thing with real devices.

推荐答案

我遇到了同样的问题.尝试

I had the same issue. Try

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

代替

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

事件处理指南:Motion事件.这对我有用.

这篇关于摇动识别在iOS 4上不起作用,在iOS 5上可以工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆