December 2012
Intermediate to advanced
834 pages
27h
English
You want your users to be able to perform a pinch gesture on a view.
Create an instance of the UIPinchGestureRecognizer class and add it to
your target view, using the addGestureRecognizer: instance method of the
UIView class:
-(void)viewDidLoad{[superviewDidLoad];self.view.backgroundColor=[UIColorwhiteColor];CGRectlabelRect=CGRectMake(0.0f,/* X */0.0f,/* Y */200.0f,/* Width */200.0f);/* Height */self.myBlackLabel=[[UILabelalloc]initWithFrame:labelRect];self.myBlackLabel.center=self.view.center;self.myBlackLabel.backgroundColor=[UIColorblackColor];/* Without this line, the pinch gesture recognizer will not work */self.myBlackLabel.userInteractionEnabled=YES;[self.viewaddSubview:self.myBlackLabel];/* Create the Pinch Gesture Recognizer */self.pinchGestureRecognizer=[[UIPinchGestureRecognizeralloc]initWithTarget:selfaction:@selector(handlePinches:)];/* Add this gesture recognizer to the view */[self.myBlackLabeladdGestureRecognizer:self.pinchGestureRecognizer];}
The .h file of the view controller is defined in this way:
#import <UIKit/UIKit.h>@interfaceDetecting_Pinch_GesturesViewController:UIViewController@property(nonatomic,strong)UIPinchGestureRecognizer*pinchGestureRecognizer;@property(nonatomic,strong)UILabel*myBlackLabel;@property(nonatomic,unsafe_unretained)CGFloatcurrentScale;@end
Pinching allows users to scale GUI elements up and down easily. For instance, ...
Read now
Unlock full access