使用 UIRefreshControl 在 UITableView 中禁用底部反弹

Disable bottom bounce in UITableView with UIRefreshControl

我想禁用 UITableView 底部反弹,我不能在故事板中使用标准 "bounce" 属性,bcs UIRefreshControl 需要顶部反弹才能工作。所以我试过 this solution:

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
if (scrollView.contentOffset.y >= scrollView.contentSize.height - scrollView.frame.size.height) {
    [scrollView setContentOffset:CGPointMake(scrollView.contentOffset.x, scrollView.contentSize.height - scrollView.frame.size.height)];
}

}

如果内容高度大于屏幕尺寸,它工作正常,但在其他情况下崩溃:

正如您在上图中看到的那样,UIRefreshControl 没有隐藏(如果 UIRefreshControll 被隐藏,uitableview 中只有 3 个单元格底部有空白 space)。我试图通过在我的方法中添加 UIRefreshControl 高度来解决这个问题,但它也没有帮助:

override func scrollViewDidScroll(scrollView: UIScrollView) {
    if scrollView.contentOffset.y >= scrollView.contentSize.height - scrollView.frame.size.height - self.refreshControl!.frame.size.height {
        scrollView.setContentOffset(CGPoint(x: scrollView.contentOffset.x, y: scrollView.contentSize.height - scrollView.frame.size.height + self.refreshControl!.frame.size.height), animated: false)
    }
}

我的顶部空白 space,RefreshControl 停止工作:

我做错了什么?谢谢

P.S。我的 viewDidLoad 方法:

override func viewDidLoad() {
    super.viewDidLoad()

    self.refreshControl = UIRefreshControl()
    self.refreshControl!.attributedTitle = NSAttributedString(string: "Обновление")
    self.refreshControl!.addTarget(self, action: "refresh:", forControlEvents: UIControlEvents.ValueChanged)
    self.edgesForExtendedLayout = UIRectEdge.None;
    tableView.allowsMultipleSelectionDuringEditing = false;
    tableView.tableFooterView = UIView()
    // menu button
    if self.revealViewController() != nil {
        menuButton.target = self.revealViewController()
        menuButton.action = "revealToggle:"
        self.view.addGestureRecognizer(self.revealViewController().panGestureRecognizer())
    }
}

目前我发现了非常愚蠢的解决方案:

override func scrollViewDidScroll(scrollView: UIScrollView) {
    if scrollView.contentSize.height > self.view.frame.size.height && scrollView.contentOffset.y >= scrollView.contentSize.height - scrollView.frame.size.height {
        scrollView.setContentOffset(CGPoint(x: scrollView.contentOffset.x, y: scrollView.contentSize.height - scrollView.frame.size.height), animated: false)
    }
}

我只在 contentSize.height > self.view.frame.size.height 时禁用弹跳,希望有人知道如何做得更好。