Detect if certain UIView was touched amongst other UIViews

Posted by Rudiger on Stack Overflow See other posts from Stack Overflow or by Rudiger
Published on 2010-05-08T07:09:03Z Indexed on 2010/05/08 7:18 UTC
Read the original article Hit count: 324

Filed under:
|
|

HI Guys,

Sorry if this has been answered elsewhere but I can't seem to get it to work.

I have 3 UIViews, layered on top of one large uiview. I want to know if the user touches the top one and not care about the other ones. I will have a couple of buttons in the second UIView and a UITable in the 3rd UIView.

Problem is I turn userInteractionEngabled on on the first view and that works, but all the other views respond in the same way even if I turn it off. If I disable userInteractionEnabled on self.view none of them respond. I also can't detect which view was touched in the touchesBegan delegate method.

my code:

UIView *aView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 150)];
aView = userInteractionEnabled = YES;
[self.view addSubview:aView];

UIView *bView = [[UIView alloc] initWithFrame:CGRectMake(0, 150, 320, 50)];
bView.userInteractionEnabled = NO;
[self.view addSubview:bView];

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
//This gets called for a touch anywhere
}

Thanks for any help.

© Stack Overflow or respective owner

Related posts about iphone

Related posts about uiview