How To Use Gestures In iPhone Application?

The application we are about to build does nothing more than detect swipes, both horizontal and vertical. Swipes will display a message across the top of the screen for a few seconds informing you swipe was detected. We are going to define a minimum gesture length in pixels, which is how far the user has to swipe before the gesture counts as a swipe.

Step 1:  Create a new project in Xcode using the View-based application template.

Step 2:  We start by defining a minimum gesture length of 25 pixels and a variance 0f 5. If the user was doing a horizontal swipe, the gesture could end up 5 pixels above or below the starting vertical position and still count as a swipe as long as the user moved 25 pixels horizontally.

 

 

 

Step 3: Double click ,xib file to pen it in Interface Builder. Make sure that the view is set to receive multi touches using the attributes inspector, and drag a Label from the library and drop it on the View Window. Next double click the label and delete its text. Control drag from the File’s Owner icon to the label, and connect it to the label outlet. Save your nib file,close  and go to the Xcode.

Step 4:  We calculate how far the use’s finger has moved both horizontally and vertically from its starting position. The function fabsf() is from the standard  C math library that returns the absolute value of a float.

 

 

Step 5: Go ahead and compile and run . If you find yourself clicking and dragging with no visible result, be patient. Click and drag straight down or straight across until you get the hang of swiping.

Figure 1: The Swipes application

Leave a Comment:

1 comment
iOS | Pearltrees says April 17, 2012

[…] – ( void ) touchesBegan : ( NSSet * ) touches withEvent : ( UIEvent * ) event { UITouch * touch = [ touches anyObject ] ; gestureStartPoint = [ touch locationInView : self.view ] ; – ( void ) touchesMoved : ( NSSet * ) touches withEvent : ( UIEvent * ) event { Step 4: We calculate how far the use’s finger has moved both horizontally and vertically from its starting position. The function fabsf() is from the standard C math library that returns the absolute value of a float. How to use Gestures in iphone application? | iPhone Tutorial | iPhone iOS4 iPad SDK Development &amp… […]

Reply
Add Your Reply