Link to the subclass of UITableView
I want to find out why UITableView jumps while scrolling.
How to perform some changes on UITableView
along with setting its contentOffset
?
This is how I set up my scrollDisplayLink
:
scrollDisplayLink = CADisplayLink(target: self, selector: Selector("scrollTable"))
scrollDisplayLink?.addToRunLoop(NSRunLoop.mainRunLoop(), forMode: NSRunLoopCommonModes)
cellForCurrentIndexPath?.hidden = true
and then within scrollTable
I do following things:
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
}
}
}
Scrolling is fine unless lines 1-4
are commented or I disable UITableViewAutomaticDimension
. When they are not commented the table jumps when currentContentOffset
is different then 0
while scrolling. Why it happens like that? Is it problem with threads or something else?
Note
UITableView
works with UITableViewAutomaticDimension
:
func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}