Home Tutorial Iphone Examples iPhone Single Tap and Double Tap Example

 
 

Share on Google+Share on Google+
iPhone Single Tap and Double Tap Example
Posted on: September 22, 2010 at 12:00 AM
Advertisement
The example discuss about single tapping / double tapping on UIView and it also explains how to represent the UIIMage in different modes such as displaying image on the Top, center or bottom of the UIView

iPhone Single Tap and Double Tap Example

The example discuss about single tapping / double tapping on UIView and it also explains how to represent the UIIMage in different modes such as displaying image on the Top, center or bottom of the UIView. You can also zoom in or out the image on single or double tap… the "UIViewContentMode" implements all these methods with the certain modes as given below…

List of given UIViewContentMode

UIViewContentModeScaleToFill
UIViewContentModeScaleAspectFit
UIViewContentModeScaleAspectFill
UIViewContentModeRedraw
UIViewContentModeCenter
UIViewContentModeTop
UIViewContentModeBottom
UIViewContentModeLeft
UIViewContentModeRight
UIViewContentModeTopLeft
UIViewContentModeTopRight
UIViewContentModeBottomLeft
UIViewContentModeBottomRight

In the example, to detect the end of tapping we'll use the UITouch method "touchesEnded:withEvent:" that tell's the receiver that one or more fingers have been lifted from the associated UIView. We'll also write the method to count the Tap.
See the code given below…

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {

//Get all the touches.
NSSet *allTouches = [event allTouches];

//Number of touches on the screen
switch ([allTouches count])
{
case 1:
{
//Get the first touch.
UITouch *touch = [[allTouches allObjects] objectAtIndex:0];

switch([touch tapCount])
{
case 1://Single tap
imgView.contentMode = UIViewContentModeCenter;
break;
case 2://Double tap.

imgView.contentMode = UIViewContentModeLeft;

break;
}
}
break;
}

}

Download code

Advertisement

Related Tags for iPhone Single Tap and Double Tap Example:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: September 22, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com