Resetting a UIScrollView with grace

I stumbled upon this by accident and it might be an already well-known technique, but as I’m not sure I am posting this up anyway.

I was tasked with providing the ability to pinch zoom and pan images in a slideshow of sorts. I had been using a simple UIImageView to handle this so I had to re-configure things slightly to accomodate. So now the UIImageView was placed inside a UIScrollView with a min zoom of 1 and max zoom of 4. No problem. I wanted to gracefully reset the zoom and pan on the control (with a double-tap or something)… simply using

scrollview.zoomScale = 1.0;

was simply too abrupt. All you need to do is throw this around it and you’ve instantly added a little grace to the operation:

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.25];
scrollView.zoomScale = 1.0;
[UIView commitAnimations];

That’s it :)

Related Posts Plugin for WordPress, Blogger...

Leave a Reply

Your email address will not be published. Required fields are marked *


seven + = 9

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>