How to snap to zoom with UIScrollView? - iphone

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.

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.

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.

Related

Keep Mapbox Current Location Fixed on Pinch to Zoom in Android

Zooming with Pinch in Mapbox Keeps Changing the center , how to achieve the same result as zooming with double-tap + scrolling Finger with Pinch too ?
the answer is to detect Zooming event and then Disable Scrolling till Zomming Ends , this works well in GoogleMaps but not properly in MapBox as the Scrolling wont get disabled (even when set to false programmatically) while zooming .
Another Way is to Add a Marker at the center of the Map the moment Zooming Starts and Removing it when it ends and show your own Marker (Probably an Image centered over the map )

Detecting if is zoom-in or zoom-out with leaflet

How can I know when the user is zooming in or zooming out? I want to start an animation if the user zooms after some level. Is it possible to know this when the event zoomstart is triggered?
How can I know when the user is zooming in or zooming out?
At every zoom level, calculate how much map.getZoom() has changed.
Is it possible to know this when the event zoomstart is triggered?
No.
Consider the following scenario: A user, using a touchscreen (phone/tablet).
The user puts two fingers down on the screen. Half a frame after, one of the fingers moves a couple of pixels towards the center, triggering a pinch-zoom with a tiny change in the zoom level.
Your code catches the zoomstart and zoom events that happen inmediately after. "I know!" - your code says - "The user is zooming out!".
And then the user starts moving their fingers wider and wider, zooming in. And your code gets confused.
But the user changes their mind, and then starts zooming out for whatever reason. And then in again. And then out again. And then they lift the fingers and the zoom snaps to a zoom level.
This is why you can not know what the final zoom level is going to be when you listen to a zoomstart or zoom event in Leaflet.

iPhone: Properly scaling lines / circle drawn in drawRect

I am drawing custom annotations over an image (circle, arrow etc) in my iPhone app. I allow pinch zooming & drag gestures for these annotations. These annotations are custom made AnnotationView with drawRect drawing circle / line etc.
I am finding issues with zooming
Try 1: The zoom is applied by scale transformation to the AnnotationView. Result: the annotations become blurred.
Try 2: To avoid blurring, I added redrawing with co-ords multiplied by scale factor instead of directly manipulating the transformation. This works without blurring, but, soon the circle etc goes out of the views bounds & is clipped.
I could use a bigger frame (size of full image), but, I am keeping the smaller frame so that I can easily move it back to position when it is dragged out of the window by user's zoom / pan gestures.
Question:
Is there a better way to manage this? I would like to zoom without blurring, while also having the ability to move it back to position if it is dragged out of original image bounds.

Detecting Zoom Level on iPhone

I'm using the UIImagePickerController to control the camera and overlay millimeter tick marks in preview for measuring closeup macro shots, and I'd like to be able to detect the current zoom level and scale it properly.
Is there any way to determine the current zoom level in camera preview?
Unfortunately no, since the UIImagePickerController API doesn't give you access to the camera zoom level, nor to any subviews or other properties that might have access to that information.
As Michael Dautermann points out, based on the answer to this question, you could use the cameraViewTransform property of UIImagePickerController to implement your own zoom by setting up the right CGAffineTransform and also the right pinch gesture to zoom in/out. Since you'd be controlling the zoom yourself, you'd always know the zoom level and be able to use it to adjust the tick marks.

finding out vertical pinch out in UIPinchgestureRecogniser?

I want to increase width of UIView,when pinching out horizontally and also height only when pinching out vertically? is it possible in UIPinchGestureRecogniser?
Not directly possible but if you were to maintain state yes. You can get the touch points using locationOfTouch:inView. Track them as he pinches and see which direction they are in. Update accordingly.