Set the maximum zoom scale on a UIImageView? - iphone

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

Related

Swift: hot to pan and zomm in/out image inside imageView

In ViewController I have a big ImageView whose image is captured with a ImagePicker. I want the user to be allowed to zoom in/out the image and then pan it but always inside the ImageView dimensions which must not enlarge, move or dwindle. I have seen I could add a ScrollView to ImageView but I can't figure out how to do that.
Moreover: is it possible to zoom in/out more than one ImageView at a time? I mean I have some smaller imageViews floating upon a bigger imageView. Is it possible to zoom everything all together?
There are plenty of excellent scrollview demo's around.
These will show you where and how to add override functions to implement what you need...
If you have different UIImage Views you can set the zoom programmatically to match the image being "zoomed" ... try experimenting with [UIImage].zoomScale. and the image offset. Its going to get complicated if they are different sizes as you will have to take account of scale when mirroring offset and zoom changes.

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.

Stop scroll image in UIScrollView when image zoom

I have a image in UIScrollView, I wants user cannot scroll image in zoom time, I read many property of UIScrollView, but I am confused.
How we stop scrolling image(horizontally or vertically) when user zoom the image in scrollView.
I already test
scroll.scrollEnabled=NO;
scroll.directionalLockEnabled = YES;
scroll.bounces=NO;
scroll.scrollEnabled = N0; stop scrolling but the task is that the user cannot scroll the image ,when user zoom the image , I need help
Thanks
You have to set your viewcontroller as scrollviews delegate. Assuming you have UIImageView that you are zooming in scrollView. What you want to do is to center it in the middle of scrollviews bounds while zooming. If you only want to disable scrolling in vertical or horizontal direction then change only x or y center of imageView
- (void)scrollViewDidZoom:(UIScrollView *)scrollView
{
self.imageView.center=CGPointMake(CGRectGetMidX(self.scrollView.bounds), CGRectGetMidY(self.scrollView.bounds));
}
I highly recommend having a look at apple video session on advanced scrollview techniques 2010, 2011 and 2012 they really explain quite well what a powerful beast UIScrollView really is. Hope this was helpful

adding a UIView on a UIScrollVIew during the zoom mode

i'm trying to place a UIView on a scrollView during its zoomed state. I want the UIView to be seen on the scrollView and also to resize along with it once the scrollView is zoomed out.. i am able to place the UIView on scrollView during the zoomed state. But the UIView is not getting resized after zooming out... Should i apply any transforms here??? can anyone help me in this please... Thank you
You can use a little trick: before zoom is started get the screenshot of the view (with subviews) that you want to zoom. Add that image to the UIImageView add return it via viewForZoomingInScrollView:. So you actually zoom the image of that view and not the one itself.
After zoom ended scale your actual view manually.
You can find out how to get screen shot from my post here

UIScrollView map with pins that stay at a fixed size?

In my app, I have a ScrollView that shows a map(just a jpeg).
On top of the ScrollView, I added some pins(UIImageView)
So far so good.
But when I zoom in, the pins also get larger.
I would like the pins to stay at a fixed size, just like the pins on the google map application on the iPhone.
How do I solve this?
Thanks!
I've been looking into this for a few days and I've come to the conclusion that there is currently no good way to do this.
First, put your pins as a direct subview of the UIScrollView. Now they'll stay the same size, but will move around when you zoom.
In OS version >=3.2 in UIScrollViewDelegate there is -scrollViewDidZoom:, where you can update the pins to the right coords as it scrolls, and this works great. But in 3.1 we're out of luck. I tried having a NSTimer going and updating the coords instead, but it's not performant on the device.
As a fallback what I do is hide the pins when zooming starts (viewForZoomingInScrollView) and when zooming ends (scrollViewDidEndZooming) update their coords and unhide them.
Make a container UIView that is the same size as the map. Add the map to the UIView with autoresizing of flexible width and height. Add all the pins as individual images, each with flexible margins. Use the container as the zooming view.
If the system autoresizeing does not retain the margin ratio then you can implement layoutSubviews in a custom container view.