Ball Move Up,Down, And Detect The Touch Event In iPhone

In this application we push the button and the ball will move up and down . Application detect the touch event also.

Step 1: Create a View base application using template. Give the application name Touch.

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: Expand classes and notice Interface Builder created the  TouchViewController class for you. Expand Resources and notice the template generated a separate nib, TouchViewController.xib for the TouchViewController.

Step 4: Open TouchViewController , add a UIView, and UILabel for display the touch event. Add IBAction method. So make the following changes in the TouchViewController.h file.

 

 

 

Step 5: Double click your TouchViewController.xib file open it to Interface Builder.   First drag the image view from the library and place it view window . Connect File’s Owner icon to the View window and select viewOne. Drag label from the library and place it to the view window, Double click it and change the name touchesLabel outlet. Now connect File’s Owner icon to the touchesLabel and select touchesLabel. Single click and bring up Attributes inspector and select ball.png. Now drag the Round Rect from the library and single click give the name Push. Select it and  bring up Connection Inspector. Drag Touch Up Inside to the File’s Owner icon and select pushToStart method.

Step 6: Make the following changes in the TouchViewController.m file.

 

 

 

Step 7: Compile and run the application in the simulator.

You can downloaded SourceCode from here Touch 2