2013-05-08 162 views
4

我想为节日做一个阵容。你可以在这里看到我想要达到的目标。 enter image description here在UITableview中水平和垂直滚动

你可以在每一个方向滚动,水平 - 垂直和由左到右角落(不知道英语的正确的字)。如果你在一节有史以来滚动其他部分应该与它滚动。

我的问题是知道你怎么能做到这一点?我正在寻找几天来得到这个工作,但没有找到一个好的解决方案...

+0

你想只水平滚动UITableViewCell,即一次一行或整个UITableview – Bonnie 2013-05-08 09:07:23

+0

整个表视图 – Steaphann 2013-05-08 09:20:03

回答

4

UITableView中的行不滚动自己内部的UITableView。一个解决方案是使用UIScrollView,然后添加UITableView。这个UIScrollView的尺寸与你的UITableView的尺寸相同,但是UIScrollView的contentSize属性将具有相同的高度,但它的宽度会更大。

enter image description here

UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectMake(x, x, x, x) style:...] 

[scrollView addSubview:tableView]; 

// Set the size of your table to be the size of it's contents 
// (since the outer scroll view will handle the scrolling). 
CGRect tableFrame = tableView.frame; 
tableFrame.size.height = tableView.contentSize.height; 
tableFrame.size.width = tableView.contentSize.width; // if you would allow horiz scrolling 
tableView.frame = tableFrame; 

// Set the content size of your scroll view to be the content size of your 
// table view + whatever else you have in the scroll view. 
// For the purposes of this example, I'm assuming the table view is in there alone. 
scrollView.contentSize = tableView.contentSize; 
+0

这将工作,但会导致表加载所有的所有行,所以它不适合长列表。只需使tableview的框架等于scrollview的边界即可。滚动视图将执行水平滚动(这就是为什么它的contentSize.width比屏幕宽),tableview将执行垂直滚动(取决于行数)。 – 2014-04-03 22:18:39

+0

你有没有找到更好的解决方案,请分享 – 2015-08-25 09:45:44