OGeek|极客世界-中国程序员成长平台

标题: ios - 仅检测一次双击手势 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 02:28
标题: ios - 仅检测一次双击手势

- (void)touchesBeganNSSet *)touches withEventUIEvent *)event {
    for (UITouch *aTouch in touches) {
        if (aTouch.tapCount >= 2) {
            // The view responds to the tap
        }
    }
}

我正在使用上面的代码来检测双击手势;但是,如何将代码设置为只发生一次?

换句话说,当您点击一次时,角色就会跳跃。当您快速连续点击两次时,角色将进行二段跳。但是,如何设置点按,以使角色不会在没有最初点按一次的情况下连续双跳并从单 View 跳得更高?



Best Answer-推荐答案


实现这一点的一个非常简单的方法是声明一个全局 bool 变量,并在检测到双击后设置其值!

类似这样的:

@interface MyViewController()
{
    bool isTapped;
}
@end

@implementation MyViewController
- (void)touchesBeganNSSet *)touches withEventUIEvent *)event 
{
    for (UITouch *aTouch in touches) {
        if (aTouch.tapCount >= 2) {
            if(!isTapped) {
                // The view responds to the tap
                isTapped = YES;
            }
        }
    }
}
@end

希望对你有帮助

关于ios - 仅检测一次双击手势,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26195349/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4