Panich Maxim Panich Maxim - 10 months ago 249
Swift Question

Disable bottom bounce in UITableView with UIRefreshControl

I want to disable UITableView bottom bounce, I can't use standard "bounce" property in storyboard, bcs UIRefreshControl needs top bounce for work. So I have tried 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)];


It works fine if content height bigger then size of screen, but crashes in other case:
enter image description here

As u see on picture above UIRefreshControl is not hidden (and there are only 3 cells in uitableview with blank space on bottom if UIRefreshControll is hidden). I have tried to resolve this problem by adding UIRefreshControl height to my method but it didn't help either:

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)

I am having blank space at top and RefreshControl stops working:

enter image description here

What am I doing wrong? Thx.

P.S. My viewDidLoad method:

override func 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 { = self.revealViewController()
menuButton.action = "revealToggle:"


At the moment I found pretty dumb solution:

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)

I disable bounce only if contentSize.height > self.view.frame.size.height , hope some1 knew how to do it better.