为什么 UITableView 滚动时会跳转?你能帮助我吗?
对于帮助我的人,我开始并稍后奖励 100 的另一个赏金:-)
如何在UITableView
设置它的同时执行一些更改contentOffset
?
这就是我设置我的方式scrollDisplayLink
:
scrollDisplayLink = CADisplayLink(target: self, selector: Selector("scrollTable"))
scrollDisplayLink?.addToRunLoop(NSRunLoop.mainRunLoop(), forMode: NSRunLoopCommonModes)
cellForCurrentIndexPath?.hidden = true
然后在scrollTable
我做以下事情:
func scrollTable() {
var newOffset = CGPointMake(currentContentOffset.x, currentContentOffset.y + scrollRate * 10)
if currentContentSize.height < frame.size.height {
newOffset = currentContentOffset
} else if newOffset.y > currentContentSize.height - frame.size.height {
newOffset.y = currentContentSize.height - frame.size.height
} else if newOffset.y < 0 {
newOffset = CGPointZero
}
contentOffset = newOffset
if coveredIndexPath != nil && coveredIndexPath! != currentIndexPath! {
let verticalPositionInCoveredCell = longPressGestureRecognizer.locationInView(cellForRowAtIndexPath(coveredIndexPath!)).y
if direction == .Down && heightForCoveredCell - verticalPositionInCoveredCell <= heightForCurrentCell / 2 {
print("moved down")
beginUpdates() //1
moveRowAtIndexPath(currentIndexPath!, toIndexPath: coveredIndexPath!) //2
currentIndexPath = coveredIndexPath //3
endUpdates() //4
}
}
}
滚动很好,除非行1-4
被注释或我禁用UITableViewAutomaticDimension
. 当他们没有被评论时,表格跳转的时间与滚动时currentContentOffset
不同。0
为什么会这样?是线程问题还是其他问题?
笔记:
UITableView
适用于UITableViewAutomaticDimension
:
func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}