gpt4 book ai didi

iphone - 如何将 iPhone 摇动手势检测限制在特定情况下?

转载 作者:行者123 更新时间:2023-11-28 19:19:50 25 4
gpt4 key购买 nike

我成功地实现了摇动手势,但现在我想限制它只在一种特定情况下激活(在我的应用程序的选项面板中)。

  • 我首先创建了 ShakeWindow 类,它是 UIWindow 的子类。在 ShakeWindow 中,我添加了 - (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event 来注册摇动手势。

  • 接下来我转到 AppDelegate.m 并编辑 window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 以使用新的 ShakeWindow 而不是 UIWindow。

它很好用,但我如何限制它的功能?我刚刚开始使用 Objective-C,并且认为自己总体上是一个新手编码员,所以在回答时请记住这一点,谢谢!

我使用 Cocos2D 作为框架,如果这些很重要,我不使用 Interface Builder。

最佳答案

我可能误会了,但是...

- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event {

if (/* conditions where my app responds to shake */) {
// respond to shake
}
// otherwise, it's like it never happened
}

关于iphone - 如何将 iPhone 摇动手势检测限制在特定情况下?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9863170/

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