I have created a Utility based application for the iphone in xcode. Basically i have a mainview and a flipside view.
On the main view i have an image as well as a button and a label to go to the flipside view.
However, how do i make the image zoomable/pinchable? All the tutorials and code i have seen has been based on a View Based Application and when i come to copy it in it just comes up with tonnes of errors.
For example, i don't have a Classes folder. Can somebody please provide some sample code for this when you choose Utility Based Application from the new project window when you open xcode.
OK, seeing as you want some code, I see it fitting to do a full tutorial (I'm bored, let's do this!).
Open up Xcode and start a new Utilities based project (DO NOT TRASH THE OLD ONE) and name it 'PinchZoomingImages' (without the quotes). Make sure ARC is turned OFF, I like to code the old fashioned way ;).
We will be using a UIScrollView with a UIImage in it. Go into the appropriately named 'MainViewController.h" and paste in this code:
We need the
UIImageView
andUIScrollView
pointers because we will be defining them in the .m file. Speak of the devil, in the .m, paste this in over the whole thing:SCREECH! Did you notice this line here?:
That will crash your project. you need to drag in an image and copy it's name verbatim (it's cAsE SeNsTiVe) in the
[UIImage imageNamed:@"//your image name + extension"]
message.Also, notice this line in the
-(void)viewDidLoad
method:This is why we put
UIScrollViewDelegate
in a pair of these: "<>" in the .h file, because we need to announce to the compiler that we want to "conform" to theUIScrollViewDelegate
protocol.And finally, hook up those IBOutlets (Please, Please hook up the view one first if it isn't already there. It's a basic and easily forgettable thing):
and here's what the final product looks like (Upon Launch):
(Upon zooming, which you can do by holding down the 'option' button in the simulator and dragging the mouse):