Springy Bouncy scrolling of UIView

Discussion in 'iPhone/iPad Programming' started by Mac Me Up, Sep 3, 2008.

  1. macrumors regular

    #1
    Ok, so I have a UIImageView in a UIView and I want them to be scrollable with my finger. I've made the image view multi touch capable and handled the
    Code:
    - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
    method. In this method I simple set the center of my view and image to the location that corresponds to how far it tells me that the users finger has moved. This works fine, and you can move it up and down with no problems.

    My question is: how do I make this 'springy' and smooth like Apple's scrolling of tables, where your flick has momentum and the view springs when it hits the end. Is there an easy way to do this or do I have to write all the code that handles this?

    At the moment my view moves to exactly where your finger stopped and no more, which feels unnatural on the iPhone.
     
  2. dwm
    macrumors newbie

    #2
    Put your image view in a UIScrollView container/superview?
     
  3. macrumors regular

    #3
    Sorry to be a N00b, but I've put my view in a UIScrollView and made that view multi touch enabled, then commented out my implementation of the move method. Now it doesn't scroll. I've looked at the documentation for the UIScrollView and it seems like it should just work?
     
  4. macrumors regular

    #4
    Ok after smacking my head into a wall for a while I figured it out. I couldn't get it to work when I created the UIScrollView in Interface Builder, but as soon as I did it manually, hey presto!

    Code:
    scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 440)]
    
     

Share This Page