How to position UITableViewCell at bottom of screen?

前端 未结 14 594
旧时难觅i
旧时难觅i 2020-12-08 03:25

There are one to three UITableViewCells in a UITableViewView. Is there a way to always position the cell(s) at the bottom of screen after rel

14条回答
  •  情深已故
    2020-12-08 03:49

    This can be done by in swift using below funcation

    func updateContentInsetForTableView(tblView: UITableView, animated: Bool) {
    
        let lastRow: NSInteger = self.tableView(tblView, numberOfRowsInSection: 0)
        let lastIndex: NSInteger = lastRow > 0 ? lastRow - 1 : 0
        let lastIndexPath: NSIndexPath = NSIndexPath(forRow: lastIndex, inSection: 0)
        let lastCellFrame: CGRect = tblView.rectForRowAtIndexPath(lastIndexPath)
        let topInset: CGFloat = max(CGRectGetHeight(tblView.frame) - lastCellFrame.origin.y - CGRectGetHeight(lastCellFrame), 0)
        var contentInset: UIEdgeInsets = tblView.contentInset
        contentInset.top = topInset
        let option: UIViewAnimationOptions = UIViewAnimationOptions.BeginFromCurrentState
        UIView.animateWithDuration(animated ? 0.25 : 0.0, delay: 0.0, options: option, animations: { () -> Void in
            tblView.contentInset = contentInset
        }) { (_) -> Void in }
    }
    

提交回复
热议问题