Reputation: 1115
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:
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:
What am I doing wrong? Thx.
P.S. My viewDidLoad method:
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())
}
}
Upvotes: 3
Views: 1833
Reputation: 1115
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.
Upvotes: 8