开发者

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];   
    开发者_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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜