我希望禁用UITableView底部弹跳,因为在storyboard中不能使用标准的“bounce”属性,因为UIRefreshControl需要顶部弹跳才能工作。所以我尝试了这个解决方案:
- (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个单元格并留有空白底部)。 我尝试通过将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)
}
}
我页面顶部有空白区域,刷新控件也停止工作了:
我做错了什么?谢谢。
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())
}
}