开发者

touchesBegan - iPhone app UIView

开发者 https://www.devze.com 2023-03-19 10:30 出处:网络
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.

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];   
    开发者_StackOverflow社区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.

0

精彩评论

暂无评论...
验证码 换一张
取 消