I am writing an iPhone application with a tab bar and a navigation bar. At some point, I push an instance of the DetailsViewController class onto the navigator controller stack to show it.
This controller creates its own hierarchy of representations in the code: the view controller property is set to UIScrollView, which contains a simple UIView (let it be called its contentView) size to contain all the content that will be displayed. At the bottom of this contentView, I have four UIButtons.
Now, when I launch the application (currently in the simulator) and scroll through the bottom of the view, the top two buttons are touch-sensitive; the third one responds to touch only at the top, and the bottom button does not respond to touch at all. By clicking in different parts of the third button, it seems that the lower 93 pixels of scrolling do not transmit touch events to its subzones.
93 is suspicious: this is also the combined height of the tab bar (49 pixels) and the navigation bar (44 pixels). However, the navigation bar and the tab bar are outside the scroll bar. Any suggestions why this might happen?
Here is the code in question:
- (void)loadView { CGRect frame = [[UIScreen mainScreen] applicationFrame]; UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:frame]; scrollView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight); scrollView.delegate = self; self.view = scrollView; UIView *contentView = [[UIView alloc] initWithFrame:scrollView.bounds]; contentView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight); [scrollView addSubview:contentView]; CGSize viewSize = contentView.bounds.size; CGSize size; CGFloat y = 0; actionsView = [[PropertyDetailActionsView alloc] initWithFrame:CGRectZero]; actionsView.autoresizingMask = (UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleWidth); actionsView.delegate = self; size = [actionsView sizeThatFits:viewSize]; actionsView.frame = CGRectMake(0, y, size.width, size.height); [contentView addSubview:actionsView]; y += size.height; [contentView setFrame:CGRectMake(0, 0, viewSize.width, y)]; scrollView.contentSize = contentView.frame.size; [contentView release]; [scrollView release]; }
source share