iPhone Single Tap and Double Tap Example


 

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

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

Ads