How to zoom image in iPhone? - iphone

I need to zoom an image in iphone...while the user double clicks on the image it will be zoomed in and on the next click it will be zoomed out....Can anybody direct me to how to do this???

You would probably have to use the size property of UIImage, triggered by UIImageView's touchesBegan method.
You can also use animations if you want the zoom effect to be smooth.
Another option could be to place your UIImageView inside a UIScrollView, or use a UIWebView.
Also, I suggest you take a look at the Three20 project. I think TTPhotoView supports zooming.

If you want to zoom and scroll your view, you need a UIScrollView. Tricking it to do what you want used to be very hard, however the problem of programmatic zooming of UIScrollView is now solved.
I have a described how to do it, created ZoomScrollView class (a drop-in subclass of UIScrollView) to encapsulate the solution and provided a working example at github.com/andreyvit/ScrollingMadness/ (the README contains a long description of two UIScrollView tricks and the reasoning behind them).

Related

Scroll screen without using UIScrollView

I've seen iOS apps that allow users to scroll around a view that is larger than the screen itself, without seeming to implement a UIScrollView mechanic. So for example, the actual image displayed on the screen is double the width of the screen, and the user can pan left and right to view all the content. Is this just a case of making the ViewController's width twice that of the screen and allowing some kind of panning via gesture recognizers? With what I'm trying to do, it seems like this would be easier that implementing a UIScrollView...
Implementing scrollview is much easier than handling pan gesture, when Apple has given built-in functionality then why you do not want to use it?
You can either use UIPangestureRecognizer or UIscrollview. The Latter option is very simple.

UIScrollView lags on iPhone

I'm trying to create a crossword app. The game runs in a UIScrollView, because the player should be able to zoom, scroll etc. The largest crossword are 21x21 which means there need to be 441 touchable tiles. What i've tried so far were to create an UIView and added it as a subView to the UIScrollView. Then I call a method that creates 441 custom UIButtons and set the backgroundImage.
Some of the UIButtons need to have a custom label overlay, so i added a UILabel and set it on top of the UIButton.
When I run the app in simulator all works as it should, but when i test it on an iPhone 4 the UIScrollView lags a lot.
I don't know if this the way to do it? Can you maybe try to guide me in the right direction of how to do this so the UIScrollView won't lag on a device.
Thanks in advance.
Big UIScrollViews are difficult to make smooth without some sort of caching mechanism, such as the one provided by UITableView.
One thing you can do, however, to make life easier for your rendering, is to make sure to use opaque backgrounds whenever possible. In stead of making a view transparent you should make it the same color as its underlying view. This is something that does help.
Also, I have experienced better performance using imageWithContentsOfFile: in stead of imageNamed: for initializing images to be used in a UIScrollView.
In order to not keep all those buttons in memory, you should work with reusable table view cells, this will really improve the scroll performance. Here's one component that could make your life easier: DTGridView, there are also others (you can check Cocoa Controls)

Handling touch events in uiscrollview

I have a UIScrollView and an UIImageView as its subview. I want to draw on the imageview in response to the single touches. And I want to zoom and pan the image view in the scroll view on pinch and pan gestures respectively. I found many solutions. But its not perfect. Please give me a straight forward solution.
use after subclassing UIScrollview.See the link.If you are doing application for iphone4 OS,try to use UIGestureRecogniser.see the sample code for it in Apple site.
If you are only using the scrollview for panning and zooming, I would suggest subclassing UIImageView to provide that functionality yourself along with the drawing. This will allow you to have finer control over it and quicker code. A scrollview is not very good at allowing complex gestures within it. (other than taps)

Zoom in out a view to a specific point iphone sdk?

I want to zoom in and out a UIVIew on to specific point something similer effect to focus + zoom in. I don't want to use UISCrollView. What is the right approach to do this if anyone could suggest.
Thanks
The right approach is to use a scroll view. If you don't want to use a scroll view, though, you can use a tiled layer. Bill Dudney has an example of that here: http://bill.dudney.net/roller/objc/entry/tiledlayer_on_the_iphone
Why don't you want to use a scroll view?

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.