TouchesEnded not working in iOS5, working fine in

2019-07-18 03:37发布

问题:

I have a custom scrollView with the following method implemented:

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

     }
  }

And in My View Controller I have the following method:

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

}

}

under iOS 4, this works perfectly, touches on the scrollview are recognized and the touchesEnded gets called in my view controller and all is right with the world. Under iOS 5x, however, the touchesEnded never gets fired. Does anyone know what the heck is going on/wrong?

回答1:

Found the Answer here, basically if you want to do what I am doing you need to pass the touchesBegan up the chain as well.. because if a viewController didn't see the touchesBegan it won't get the TouchesEnded... So I modified the custom ScrollView to throw up the touchesBegan and everything now works fine in 5.0

Reference:

UIView touch handling behavior changed with Xcode 4.2?