【问题标题】:TouchesEnded not working in iOS5, working fine in iOS4TouchesEnded 在 iOS5 中不工作,在 iOS4 中工作正常
【发布时间】:2012-07-07 17:51:06
【问题描述】:

我有一个自定义的滚动视图,实现了以下方法:

  - (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
 {
     //if not dragging send it on up the chain
     if(!self.dragging){
    [self.nextResponder touchesEnded:touches withEvent:event];
     }else {
        [super touchesEnded:touches withEvent:event];

     }
  }

在我的视图控制器中,我有以下方法:

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


NSLog(@"TOUCH");
//---get all touches on the screen---

NSSet *allTouches = [event allTouches];



//---compare the number of touches on the screen---

switch ([allTouches count])

{

        //---single touch---

    case 1: {

        //---get info of the touch---

        UITouch *touch = [[allTouches allObjects] objectAtIndex:0];



        //---compare the touches---

        switch ([touch tapCount])

        {

                //---single tap---

            case 1: {
                NSLog(@"Single");

                [self mySingleTapMethod];
            } break;



                //---double tap---

            case 2: {

                [self myDoubleTapMethod];
            } break;

        }

    }  break;

}

}

在 iOS 4 下,这可以完美运行,滚动视图上的触摸被识别,并且 touchesEnded 在我的视图控制器中被调用,一切正常。然而,在 iOS 5x 下,touchesEnded 永远不会被触发。有谁知道到底发生了什么/错了?

【问题讨论】:

  • IOS 5 中的问题似乎与对 ScrollView 的调用从未到达 ViewController 中的 touchesEnded .. scrollView 中的 touchesEnded 确实被触发了。

标签: ios5 ios4 scrollview touches


【解决方案1】:

在这里找到了答案,基本上,如果你想做我正在做的事情,你也需要将 touchesBegan 向上传递..因为如果 viewController 没有看到 touchesBegan 它就不会得到 TouchesEnded .. . 所以我修改了自定义的 ScrollView 以抛出 touchesBegan,现在一切都在 5.0 中正常工作

参考:

UIView touch handling behavior changed with Xcode 4.2?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-03
    • 2013-06-29
    • 2021-06-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多