gpt4 book ai didi

ios - 摇晃识别在 iOS 4 上不起作用,但在 iOS 5 上有效

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:24:31 25 4
gpt4 key购买 nike

我在我的应用程序中集成了摇晃识别功能。我已将它放在我的 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 模拟器中运行它,它不起作用。与真实设备相同。

最佳答案

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

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

代替

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

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

关于ios - 摇晃识别在 iOS 4 上不起作用,但在 iOS 5 上有效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8458616/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com