iphone/ipad - parent UIView is blocking touches from getting to subviews - why?

sol picture sol · Sep 6, 2010 · Viewed 10.3k times · Source

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.

Answer

sol picture sol · Sep 10, 2010

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