【问题标题】:UIScrollView Inside UIView set as tableHeaderView not scrollingUIScrollView 里面的 UIView 设置为 tableHeaderView 不滚动
【发布时间】:2013-02-28 05:46:31
【问题描述】:

我遇到了一个问题,我在底部有一个 uiview,我需要添加一些我想保持静态的标签。然后我在 uiview 顶部添加一个滚动视图,其中包含一些可滚动的内容。最后,我将原始 uiview 设置为表 headerView。尽管 contentSize 正确,但 scrollView 没有滚动。

UIView *header=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 100*objects.count, 150)];
        [header setBackgroundColor:[UIColor redColor]];

    //set up scroll view
    UIScrollView *scrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 20, 100*objects.count, 110)];
    scrollView.delegate=self;
    scrollView.contentSize=CGSizeMake(100*objects.count, scrollView.frame.size.height);
    [scrollView setUserInteractionEnabled:YES];
    [scrollView setScrollEnabled:YES];

    [header addSubview:scrollView];

    [scrollView setShowsHorizontalScrollIndicator:YES];
    [self.tableView setTableHeaderView:header];

    //add stuff to scroll view

但是,当我将 scrollView 设置为 tableHeaderView 时,滚动效果很好

    [self.tableView setTableHeaderView:scrollView];

谁能建议我如何将原始 botton uiview 设置为标题视图并让 scrollView 仍然有效?

【问题讨论】:

  • 你能发一张截图让我们更好地了解吗?
  • 没什么可看的,只是滚动视图没有滚动
  • 可能是边界问题。

标签: iphone xcode uitableview uiview uiscrollview


【解决方案1】:

解决方案是使用滚动视图的 scrollViewDidScroll 委托方法,并根据滚动量调整内容偏移量。有点 hacky,仍然不知道为什么会发生这个滚动视图问题,但它现在有效。

看起来像

-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{

    [self.featuredLabel setFrame:CGRectMake(5+scrollView.contentOffset.x, 5, self.view.frame.size.width, 18)];
    [self.recentLabel setFrame:CGRectMake(5+scrollView.contentOffset.x, 100, self.view.frame.size.width, 18)];

}

找不到提到它的so帖子

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-21
    • 2013-10-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-03
    相关资源
    最近更新 更多