UIImageView With Touches In iPhone

In this application we will see how to touch function implemented in the ImageView. let see how it will be worked.

Step 1: Create a Window base application using template. Give the application name “TouchImage”.

Step 2: Xcode automatically creates the directory structure and adds essential frameworks to it. You can explore the directory structure to check out the content of the directory.

Step 3: We need to add the resource file called as “natural.png” into the resource folder. Select resources and add files existing sources and select the natural.png.

Step 4: Add UIViewController class to the project.Choose New file -> Select cocoa touch classes group and then select UIViewController subclass and corresponding .xib file. Give the name “TouchImageViewController”.

Step 5: Open the AppDelegate.h file, define the “TouchImageViewController” class in the file. So make the following changes in the file.




Step 6: Double click your TouchImageViewController.xib file open it to the Interface Builder. Drag Image View from the library and place it to the view window. Then select the view and bring up Attributes Inspector, select the image. Connect the File’s Owner icon to the view icon select the view and drag File’s Owner icon to the Image View and select displayImage. Now save the nib file, close it , go back to the Xcode.

Step 7: Make the following changes in the AppDelegate.m file.




Step 8: Now open the TouchImageViewController.h file, and added the UIImageView for display the image, two variable timer, and distance, define two methods. So make the following changes:




Step 9: Make the following changes in the TouchImageViewController.m file.




Step 10: Now compile and run the application in the Simulator.

You can downloaded SourceCode from here TouchImage 2

Leave a Comment: