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

Leave a Comment:

5 comments
Rahul Prakash Bhilane says March 4, 2010

Really a very fundamental resource for a beginner like me . I will be very happy if i get an assistance from you for developing the iphone application.I am in search of a hard copy of iphone book , if you have any suggestions regarding this then please tell me about that.

Thanks and Regards
Rahul P Bhilane

Reply
Eugene says June 18, 2010

Hi, very similar to the one I’m trying to develop. Great help! However, may I know what changes do I have to make in order to have a constant moving ball, rather than in wave form. Hope to hear from you soon.

Regards,
Eugene

Reply
Sushant says June 18, 2010

You need to change the value of “setAnimationRepeatCount”

Reply
Eugene says June 21, 2010

Thank you! Another question, if I want to move in accordance to x, y direction at a constant speed. How should I go about doing it?

Reply
surender says November 27, 2010

Hi,

i want to display the one pin button on google map where i can touch the map,
could please send me the source code for this.

Thanks
Surender.

Reply
Add Your Reply