UIScrollView里面UIView设置为tableHeaderView不滚动
问题描述:
我遇到了一个问题,我有一个uiview在底部,我需要添加一些标签,我想保持静态。然后,我在uiview的顶部添加一些可滚动内容的滚动视图。最后,我将原始uiview设置为表头headerView。即使正确的contentSize,scrollView也不会滚动。UIScrollView里面UIView设置为tableHeaderView不滚动
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
然而,当我只设置滚动视图作为tableHeaderView,滚动完美的作品
[self.tableView setTableHeaderView:scrollView];
任何人都可以建议我怎么可以设置原来钮的UIView作为标题视图,并有滚动视图仍然工作?
答
解决方案是使用scrollViewDidScroll委托方法滚动视图并调整滚动量的内容偏移量。有点哈克,仍然不知道为什么这个scrollview问题正在发生,但它现在工作。
看起来像
-(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)];
}
找不到提到所谓后
你能后的截图,所以我们可以得到更好的主意吗? – 2013-03-12 15:56:40
除了滚动视图没有滚动 – Live2Enjoy7 2013-03-12 16:58:51
可能是一个边界问题没有真正看到。 – Avigit 2013-03-12 17:14:56