TouchesEnded在iOS5中不起作用,在iOS4中运行良好

时间:2012-07-07 17:51:07

标签: ios5 ios4 scrollview touches

我有一个自定义scrollView,实现了以下方法:

  - (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];

     }
  }

在My View Controller中,我有以下方法:

-(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永远不会被解雇。有谁知道这是怎么回事?

1 个答案:

答案 0 :(得分:3)

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

参考:

UIView touch handling behavior changed with Xcode 4.2?