我正在编写一个带有标签栏和导航栏的iPhone应用程序。在某个时刻,我正在将一个DetailsViewController类的实例推送到导航控制器堆栈上以显示它。
该控制器在代码中创建其视图层次结构:控制器的view
属性设置为UIScrollView,其中包含一个简单的UIView(让我们称之为“contentView”),其大小可以容纳要显示的所有内容。在这个contentView的底部,我有四个UIButtons。
现在,当我运行应用程序(目前在模拟器中),并滚动到视图的底部时,顶部的两个按钮响应触摸;第三个仅响应触摸的顶部,而下部按钮根本不响应触摸。通过单击第三个按钮的各个部分,滚动视图的低93像素似乎没有将触摸事件传递到其子视图。
93是可疑的:它也是标签栏(49像素)和导航栏(44像素)的组合高度。然而,导航栏和标签栏位于滚动视图之外。有任何建议可能会发生这种情况吗?
以下是相关代码:
- (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;
/* Snip creating various labels and image views */
/* Actions view creates and lays out the four buttons; its sizeThatFits:
** method returns the frame size to contain the buttons */
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];
}