Search code examples
iphoneiosuiviewuiviewcontrollertouchesbegan

touchesBegan - iPhone app UIView


I have a touchesBegan: method which works fine. However I recently added a UIView (a button) to my UIViewController and now the button isn't registering taps, however my touchesBegan: method is.

How can I tell my touchesBegan: method to avoid the button?

Here is my current touchesBegan: method:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event  {
    NSLog(@"touches began");
    UITouch *touch = [touches anyObject];   
    switch ([touch tapCount]) 
    {
        case 1:
            break;

        case 2:
            if(something)
                [doing something];

            break;

        default:
            break;
    }
}

Solution

  • Make sure that the button is in front ([self.view bringSubviewToFront: myButton]). Then you can ask the touch in which in view it occurred:

    if ([touch.view isEqualTo: myButton]) {
        NSLog(@"touch was on button");
    }