views:

174

answers:

3

I have a UIView which has a bunch of subviews. The subviews should be able to receive touch events, but for some reason the parent UIView takes the touch and does not pass it on. I have created it in a very standard way like I always create views:

UIView *myView = [[UIView alloc] initWithFrame:CGRectMake(0,0,1024,768)];
    self.mainView = myView;
    [myView release];

    [self.view addSubview:self.mainView];

Then I create subviews and add them as normal:

[self.mainView addSubview:someOtherView];

I know self.mainView is getting the touch events when I listen in the main UIWindow:

VIEW: <UIView: 0x8d34aa0; frame = (0 0; 1024 768);

But why in the world can I not get the subviews to receive touches? I don't understand why this happens sometimes. I am not changing any default properties of mainView.

A: 

Does you touch handlers call the superclass handlers?

e.g. in your touchesBegan, calling:

[super touchesBegan:touches withEvent:event];
hotpaw2
I don't have any touch handlers. The subviews just are not responding to touches. For example a GestureRecognizer on one of the subviews doesn't work.
sol
A: 

A UIView has userInteractionEnabled set to YES by default. Set to NO to ignore any touches in that view and let subviews get a piece of the action.

Warren Burton
A: 

Had to do with the frame of the parent view. If the frame doesn't enclose the subviews they won't receive touches.

sol