0

Here I have following code, trying to change the value of targetContentOffset, however I only got the println() working, view still not changed after I set offset

func scrollViewWillEndDragging(scrollView: UIScrollView!, withVelocity velocity: CGPoint, targetContentOffset: UnsafePointer<CGPoint>) {

    println( "got something" )
    targetContentOffset.memory.x = 200
    targetContentOffset.memory.y = 200
}

update:

I am able to scroll the view automatically when I did following. However when I set animated to true it doesn't work.

func scrollViewWillEndDragging(scrollView: UIScrollView!, withVelocity velocity: CGPoint, targetContentOffset: UnsafePointer<CGPoint>) {
    targetContentOffset.memory = CGPointMake( CGFloat( 156.0 ) , CGFloat( 0.0 ) )
    scrollView.setContentOffset( CGPointMake( CGFloat( 156.0 ) , CGFloat( 0.0 ) ), animated: false )
}
Siming Chen
  • 1
  • 1
  • 2

2 Answers2

0

I deleted cell from my storyboard, and rewrote everything in code. Somehow it worked.

Siming Chen
  • 1
  • 1
  • 2
0

You shouldn't be calling scrollView.setContentOffset inside of scrollViewWillEndDragging. scrollViewWillEndDragging is called automatically when user scrolling has stopped, and it gives you the opportunity to modify the targetContentOffset accordingly.

This should animate the scrollView's contentOffset to the modified targetContentOffset automatically:

func scrollViewWillEndDragging(scrollView: UIScrollView!, withVelocity velocity: CGPoint, targetContentOffset: UnsafePointer<CGPoint>) {
    targetContentOffset.memory = CGPointMake(CGFloat(156.0), CGFloat(0.0))
}
Mark
  • 7,167
  • 4
  • 44
  • 68