targetContentOffset slow decelerating.

Hello.


I´m using, scrollViewWillEndDragging for changing the target when decelerating. The problem is the animation is ending with pretty slow decelerating (some pixels) even when decelerationRate is fast.


override func viewDidLoad() {

super.viewDidLoad()

// Do any additional setup after loading the view, typically from a nib.

self.CollectionView.decelerationRate = .fast

}


func scrollViewDidScroll(_ scrollView: UIScrollView) {

print("Current contentOffset: \(scrollView.contentOffset.x)")

}


func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>)

{

let target = targetContentOffset.pointee.x

let spaceSize: CGFloat = 10 + 828.0


let page = target / spaceSize


........


targetContentOffset.pointee.x = spaceSize * CGFloat(finalPage)


print("Target: \(targetContentOffset.pointee.x)")

}


Its possible to fix this?


Thanks.


EDIT: This is the log, like you can see yourself last pixels are decelerating with 0.5 pixels making the animation weird and bugged.


Target: 838.0

Current contentOffset: 197.0

Current contentOffset: 295.0

Current contentOffset: 378.0

Current contentOffset: 448.0

Current contentOffset: 507.5

Current contentOffset: 558.0

Current contentOffset: 600.5

Current contentOffset: 636.5

Current contentOffset: 667.0

Current contentOffset: 692.5

Current contentOffset: 714.5

Current contentOffset: 733.0

Current contentOffset: 749.0

Current contentOffset: 762.0

Current contentOffset: 773.5

Current contentOffset: 783.0

Current contentOffset: 791.0

Current contentOffset: 797.5

Current contentOffset: 803.5

Current contentOffset: 808.5

Current contentOffset: 812.5

Current contentOffset: 816.0

Current contentOffset: 819.0

Current contentOffset: 821.5

Current contentOffset: 823.5

Current contentOffset: 825.5

Current contentOffset: 827.0

Current contentOffset: 828.0

Current contentOffset: 829.0

Current contentOffset: 830.0

Current contentOffset: 831.0

Current contentOffset: 831.5

Current contentOffset: 832.0

Current contentOffset: 832.5

Current contentOffset: 833.0

Current contentOffset: 833.5

Current contentOffset: 834.0

Current contentOffset: 834.5

Current contentOffset: 835.0

Current contentOffset: 835.5

Current contentOffset: 836.0

Current contentOffset: 836.5

Current contentOffset: 837.0

Current contentOffset: 837.5

Current contentOffset: 838.0

I've got the same issue - any luck solving this?

Did you ever find a solution?

targetContentOffset slow decelerating.
 
 
Q