简体   繁体   中英

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

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");
}

I had the same problem. When I moved my button to the front (in code via UIViewController.bringSubviewToFront) the touchesBegan no longer was fired when I clicked on the button. I'm running Xcode 4.2, in the simulator.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM