简体   繁体   English

当单元格滚动时,iOS跳转到UITableView中的下一个单元格

[英]iOS Jump to next cell in UITableView when cell scrolled

I would like to implement a UITableView with cells that are full screen. 我想用全屏单元格实现UITableView。 When the user moves the cell up a portion, I would like to jump to the next cell as opposed to allowing it to scroll naturally. 当用户将单元格向上移动一部分时,我想跳到下一个单元格,而不是让它自然滚动。

I can't see a great deal of questions or answers out there on this, and perhaps it's because it's a daft idea, but the client wants to see it and the designer has designed it as such so I really must try. 我对此没有太多疑问或答案,也许是因为这是一个愚蠢的想法,但是客户希望看到它,而设计师已经如此设计了它,所以我真的必须尝试。

Does anyone have ANY suggestions on how to implement this? 有没有人对如何实现这个有任何建议?

Thanks. 谢谢。 (and thanks for pointing out my ignorance in not saying thanks!) (感谢您指出我的无知而不是说谢谢!)

If your cells are going to be the same size as your tableView's height, set the pagingEnabled property to YES . 如果单元格的大小将与tableView的高度相同,则将pagingEnabled属性设置为YES This will make it snap to a full cell on each vertical swipe. 这将使其在每次垂直滑动时捕捉到一个完整的单元格。 I would ensure that the height is exactly full-screen if you do this, otherwise you'll end up with some weird offsets as you scroll. 如果这样做,我将确保高度完全全屏显示,否则滚动时会出现一些怪异的偏移。

- (void)viewDidLoad
{
    [super viewDidLoad];
    // or somewhere similar
    self.tableView.pagingEnabled = YES;
}

...

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return self.tableView.frame.size.height;
}

It actually isn't a terrible idea- you could achieve similar functionality with a paging scroll-view, but this has the advantage of not needing to have all of your data loaded at once. 这实际上不是一个糟糕的主意-您可以通过分页滚动视图实现类似的功能,但这具有不需要一次加载所有数据的优点。


Edit: I also had to make sure to disable automaticallyAdjustsScrollViewInsets on the controller, otherwise I had an undesired initial offset for the first cell, just in case you run in to that as well. 编辑:我还必须确保在控制器上automaticallyAdjustsScrollViewInsets禁用automaticallyAdjustsScrollViewInsets ,否则我的第一个单元格会有不希望的初始偏移量,以防万一您也遇到了这种情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM