UITableView page size when paging enabled

后端 未结 5 1673
攒了一身酷
攒了一身酷 2021-01-31 12:10

I\'m facing with a simple but tedious problem. What I\'m trying to do is make an UITableView to page like an UIScrollView but enabling paging doesn\'t help me so much because I

5条回答
  •  隐瞒了意图╮
    2021-01-31 12:37

    Simple but efficient:

        - (void)scrollViewDidEndDecelerating:(UITableView *)tableView {
                int tomove = ((int)tableView.contentOffset.y%(int)tableView.rowHeight);
                if(tomove < tableView.rowHeight/2) [tableView setContentOffset:CGPointMake(0, tableView.contentOffset.y-tomove) animated:YES];
                else [tableView setContentOffset:CGPointMake(0, tableView.contentOffset.y+(tableView.rowHeight-tomove)) animated:YES];
        }
    
        - (void)scrollViewDidEndDragging:(UITableView *)scrollView willDecelerate:(BOOL)decelerate {
                if(decelerate) return;
    
                [self scrollViewDidEndDecelerating:scrollView];
        }
    

提交回复
热议问题