【问题标题】:touchesEnded called when any part of the screen is tapped with 2 fingers at the same timetouchesEnded 当两根手指同时点击屏幕的任何部分时调用
【发布时间】:2016-05-29 09:08:13
【问题描述】:

我发现触摸事件的这种最奇怪的行为。 甚至还没有分配目标视图 touchesEnded 将通过用 2 根手指而不是 1 根,必须是 2 根手指点击屏幕的任何部分来调用...然后它会跳过 touchesBegan,调用 touchesEnded。 我什至检查了目标视图的 userInteraction 是否设置为 YES 但没有,显然它设置为 NO 因为默认情况下它是 NO 但无论如何它都没有分配。

当目标视图已经分配和定位等时,所有这些都不会发生。

有人经历过吗? 为什么会发生这种情况,我是否必须分配属性以防止其触摸事件像疯了一样被随机调用? 另外,为什么这种奇怪的行为需要同时用两根手指而不是一次轻敲……这并不重要,但我只是很好奇。

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{

UITouch *touch = [[event allTouches] anyObject];

if (touch.view == self.buttonStartButton) {

    NSInteger levelUp = [self.levelModel checkForLevelUp];
    if (levelUp == 0) {
        [self byeGameContainer];
    }
    else {
        [self.delegate levelingUp];
    }
}}

【问题讨论】:

    标签: objective-c uiview uitouch touchesbegan touchesended


    【解决方案1】:

    因此,尝试分配目标并将其框架设置在屏幕边界之外不起作用 touchesBegan 和 touchesEnded 在点击屏幕的任何部分时仍会被调用。我什至设置了它的 userInteractionEnabled = NO 但触摸事件仍然会被调用。

    最终这样做了,这确实有效。 通过检查目标属性是否已分配,触摸事件最终不会在不应该/不应该调用时被调用。

    -(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
    

    UITouch *touch = [[event allTouches] anyObject];

    if (touch.view == self.buttonStartButton && self.buttonStartButton != nil) {

    NSInteger levelUp = [self.levelModel checkForLevelUp];
    if (levelUp == 0) {
        [self byeGameContainer];
    }
    else {
        [self.delegate levelingUp];
    }
    

    }}

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-12-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-27
      • 1970-01-01
      相关资源
      最近更新 更多