gpt4 book ai didi

ios - 运动开始 :withEvent: not called in AppDelegate in iOS 10

转载 作者:可可西里 更新时间:2023-11-01 03:31:01 25 4
gpt4 key购买 nike

我曾经通过简单地实现这个方法来检测来自 AppDelegate 的摇动 Action :

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

在 iOS 8 和 9 中运行良好。但是在 iOS 10 中不再运行。我也尝试添加

- (BOOL)canBecomeFirstResponder {
return YES;
}

但这并没有帮助。虽然这在 UIViewControllers 中工作正常。 iOS 10 中有什么变化吗,还是只是一个错误?

最佳答案

我遇到了和你一样的问题。我现在使用 UIWindow,而不是在 AppDelegate 上实现它,它适用于 iOS 8-10。也许这对您也可行?

extension UIWindow {

override open var canBecomeFirstResponder: Bool {
return true
}

override open func motionBegan(_ motion: UIEventSubtype, with event: UIEvent?) {
if motion == .motionShake {
//logic here
}
}
}

如果你想做得更干净,你可以在应用程序上设置一个专门版本的 UIWindow。

关于ios - 运动开始 :withEvent: not called in AppDelegate in iOS 10,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39518529/

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