【问题标题】:How to extend tap to handle continuous touches?如何延长点击以处理连续触摸?
【发布时间】:2014-01-16 09:40:00
【问题描述】:

当屏幕被“点击”时,我正在使用下面的代码发射弹丸(在基于 Sprite Kit 的游戏中),这一切正常。但是我想扩展它,以便在用户“触摸并按住屏幕”时重复调用 handleTap 有人能指出我正确的方向吗?

// INITIAL SETUP
UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];
[tapRecognizer setNumberOfTapsRequired:1];
[tapRecognizer setNumberOfTouchesRequired:1];
[view addGestureRecognizer:tapRecognizer];

.

// WHEN TAPPED
- (void)handleTap:(UITapGestureRecognizer *)recognizer {
    NSLog(@"%s", __PRETTY_FUNCTION__);
    [self setupAndFireProjectile];
}

【问题讨论】:

    标签: ios sprite-kit uitapgesturerecognizer


    【解决方案1】:

    改用UILongPressGestureRecognizer

    // INITIAL SETUP
    UILongPressGestureRecognizer *recognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleTouch:)];
    [view addGestureRecognizer:recognizer];
    

    .

    // WHEN TAPPED
    - (void)handleTouch:(UILongPressGestureRecognizer *)recognizer {
        NSLog(@"%s", __PRETTY_FUNCTION__);
        [self setupAndFireProjectile];
    }
    

    或者使用UIResponder'stouchesBegan:withEvent:touchesEnded:withEvent:方法:

    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
         // Start shooting
    }
    
    - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
         // End shooting
    }
    

    【讨论】:

    • 谢谢安德烈,非常感谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-03-28
    • 1970-01-01
    • 2011-07-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多