UIScrollView. How Can I Tell Zoom Out From Zoom In? - ios5

On iOS I have a UIScrollView subclass. During a zoom gesture I need to distinguish zoom-out from zoom-in. What is the best way to do this?
Thanks,
Doug

In UIScrollViewDelegate's scrollViewWillBeginZooming:withView:, store the current zoomScale of your UIScrollView; compare the stored value to the zoomScale in the scrollViewDidEndZooming:withView:atScale: to determine if it was a zoom in or a zoom out. If the value has increased, it was a zoom in; otherwise, it was a zoom out.

Related

How to zoom a selected area of image like pupil meter?

I have to show in zoom of a selected area of image continuously. Means if you are changing position simultaneously zoom also to be change. I don't know how to implement this.
UIScrollView has a great method - zoomToRect:animated: - that allows you to zoom on a specific rect. If you have a UIImageView sitting on a UIScrollView then you can zoom around the image view using this one simple method.

UIScrollView zoomToRect vs setZoom

If I have a UIScrollView, and I want to zoom in on a location, is there any difference between just setting the zoom on scrollview like
self.scrollView.zoomScale = MY_NEW_ZOOM;
versus calculating a new rectangle within the zoom to zoom in on, and using
zoomToRect:
Thanks.
zoomScale just sets the zoom scale and doesn't change the content offset.
zoomToRect: will change the zoom scale and the content offset such that the rect you have given will be visible.
Just as a heads up, you may want to ensure that the size of the rect you pass in zoomToRect: is the size of the scrollview's frame. Otherwise the Zoom and Content Offset might not end up where you expect it.

Set the maximum zoom scale on a UIImageView?

Is there a way to set the maximum zoom level on a UIImageView?
I think imageviews don't really have the funcionality to zoom, most likely you'll want to slap down a uiscrollview and then insert the imageview as a subview, at that point you'll be able to set the max/min zoom scale on the scrollview. There is an apple sample code project called scrolling that is pretty simple example of scrollviews and imageviews:
http://developer.apple.com/library/ios/#samplecode/Scrolling/Introduction/Intro.html
hope that helps.
nick

UIScrollView zoom after rotation

Allright, i have a UIScrollView with some drawings inside. the zoom and scroll works fine until i zoom in and then rotate. after the rotation zoom is fine but when i zoom back my drawings shrink more than i intend them to.
So basically, when i zoom out after rotation the view gets smaller than the screen.. how can i fix this problem ? any idea ?
I tried _scrollView.clipsToBounds = YES; but not working after the rotation.
Thanks
Have you tired to set min/max zoom scale on the UIScrollView ? Assuming you have a reference to the UIScrollView you can set the minimum zoom scale. This will ensure that when you zoom out you drawings won't shrink more than you want.
scrollView.minimumZoomScale = 1.00;

How do I reset (i.e. un-zoom) a UIScrollView?

I have a UIScrollView that contains an image and a segmented control that allows the user to switch the image inside of the ScrollView. If I just swap the image out inside of the UIImageView, it will display the new image in the zoomed-in state. How do I reset the UIScrollView back to its un-zoomed-in state?
I have a detailed discussion of how (and why) UIScrollView zooming works at github.com/andreyvit/ScrollingMadness/.
(The link also contains a description of how to programmatically zoom UIScrollView, how to emulate Photo Library-style paging+zooming+scrolling, an example project and ZoomScrollView class that encapsulates some of the zooming magic.)
Quote:
UIScrollView does not have a notion of a “current zoom level”, because each subview it contains may have its own current zoom level. Note that there is no field in UIScrollView to keep the current zoom level. However we know that someone stores that zoom level, because if you pinch-zoom a subview, then reset its transform to CGAffineTransformIdentity, and then pinch again, you will notice that the previous zoom level of the subview has been restored.
Indeed, if you look at the disassembly, it is UIView that stores its own zoom level (inside UIGestureInfo object pointed to by the _gestureInfo field). It also has a set of nice undocumented methods like zoomScale and setZoomScale:animated:. (Mind you, it also has a bunch of rotation-related methods, maybe we're getting rotation gesture support some day soon.)
However, if we create a new UIView just for zooming and add our real zoomable view as its child, we will always start with zoom level 1.0. My implementation of programmatic zooming is based on this trick.
If you're not redrawing your view on the completion of the pinch zooming event, then the zoom factor is being set by the transform property of the view you return from the viewForZoomingInScrollView: delegate method. To reset this zoom, set the value of the view's transform property to CGAffineTransformIdentity.
Beware, though, that your next pinch-zooming operation will start where the previous pinch-zoom left off (that is, your new scale will be ignored). To work around this, you may need to implement some of what I describe here.