UITableView page size when paging enabled

后端 未结 5 1789
攒了一身酷
攒了一身酷 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:36

    This works like real paging:

    - (void)scrollViewWillEndDragging:(UIScrollView *)scrollView 
                         withVelocity:(CGPoint)velocity
                  targetContentOffset:(inout CGPoint *)targetContentOffset
    {
        int tomove = ((int)targetContentOffset->y % (int)self.tableView.rowHeight);
        if(tomove < self.tableView.rowHeight/2)
            targetContentOffset->y -= tomove;
        else 
            targetContentOffset->y += (self.tableView.rowHeight-tomove);
    }
    

    and make this in -viewDidLoad:

    self.tableView.decelerationRate = UIScrollViewDecelerationRateFast;
    

提交回复
热议问题