Hilton Campbell
Hilton Campbell

Reputation: 6095

How to snap to zoom with UIScrollView?

I have a UIScrollView with a content view that the user can zoom in/out. The min zoom level is less than 1, and the max zoom level is greater than 1.

It is easy for the user to zoom all the way in, or all the way out. What can I do to get the UIScrollView to snap to zoom level 1 as well? Not just when the the user lifts their fingers, but as the they are zooming in/out as well.

Upvotes: 1

Views: 1039

Answers (2)

Alex Zavatone
Alex Zavatone

Reputation: 4323

The trick is to override or disable the pinch and add your own. When you start a pinch gesture, you DO NOT update the display and resize the image until the pinch is complete, then issue your zoomToRect.

Upvotes: 0

MiguelB
MiguelB

Reputation: 1913

Write a method, that gets called every time the user stops zooming, which then checks to see if the current zoom scale is very close to 1.0 (like something between 0.8 and 1.2). If this returns true, the zoom scale is set exactly to 1.0 to snap.

Upvotes: 2

Related Questions