代码之家  ›  专栏  ›  技术社区  ›  adurdin

uiScrollView底部的uiButtons未接收到触摸

  •  4
  • adurdin  · 技术社区  · 16 年前

    我正在编写一个带有标签栏和导航栏的iPhone应用程序。在某个时刻,我将detailsViewController类的一个实例推到导航控制器堆栈上以显示它。

    此控制器在代码中创建其视图层次结构:控制器的 view 属性设置为uiScrollView,它包含一个普通的uiView(我们称之为“ContentView”),其大小可容纳要显示的所有内容。在这个ContentView的底部,我有四个ui按钮。

    现在,当我运行应用程序(目前在模拟器中)并滚动到视图的底部时,顶部的两个按钮响应触摸;第三个按钮只响应顶部的触摸,而下部的按钮根本不响应触摸。通过单击第三个按钮的各个部分,滚动视图中较低的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];
    }
    
    1 回复  |  直到 16 年前
        1
  •  4
  •   Joost    16 年前

    正如我昨天在Twitter上建议的那样,这可能与ActionsView的灵活底部利润率有关。

    这个建议没有解决这个问题,但它引导了正确的方向。通过删除ContentView的灵活高度,问题得以解决。

    所以如果有人有类似的问题,试着玩你的自动调整大小的面具。