设置UITableView的内容偏移在滚动时不起作用(Setting content offset of a UITableView not working when it's scrolling)
这是我的代码
// 1 func scrollViewDidEndDragging(scrollView: UIScrollView, willDecelerate decelerate: Bool) { scrollTableView() } // 2 @IBAction func buttonPressed() { scrollTableView() } // 3 func scrollTableView() { tableView.setContentOffset(CGPointZero, animated: false) // tableView.scrollRectToVisible(CGRect(x: 0, y: 0, width: 1, height: 1), animated:true) // does not work either }即使调用方法1 (调用方法3),表视图也会继续自然滚动减速直到停止。 它并没有将自己定位在我想要的地方。
当表视图不滚动并且我通过按下按钮调用方法2时 ,它确实获得其内容偏移设置并且它位于应该的位置。
如何通过在方法1中调用来使其工作?
谢谢
Here's my code
// 1 func scrollViewDidEndDragging(scrollView: UIScrollView, willDecelerate decelerate: Bool) { scrollTableView() } // 2 @IBAction func buttonPressed() { scrollTableView() } // 3 func scrollTableView() { tableView.setContentOffset(CGPointZero, animated: false) // tableView.scrollRectToVisible(CGRect(x: 0, y: 0, width: 1, height: 1), animated:true) // does not work either }Even method 1 (who calls method 3) being called, the Table View continues its natural scrolling decelerating until it stops. It does not position itself where I want.
When the Table View is not scrolling and I call method 2 by pressing a button it does get its content offset set and it positions where it should.
How can I get it to work by being called in the method 1?
Thanks
最满意答案
如果我把你弄好了以下应该有效:
func scrollViewWillBeginDecelerating(scrollView: UIScrollView) { scrollTableView() }if i got you right the following should work:
func scrollViewWillBeginDecelerating(scrollView: UIScrollView) { scrollTableView() }更多推荐
发布评论