December 2012
Intermediate to advanced
834 pages
27h
English
You want the users of your application to be able to move GUI elements around using their fingers.
Pan gestures are continuous movements of fingers on the screen; recall that swipe gestures were discrete gestures. This means the method set as the target method of a pan gesture recognizer gets called repeatedly from the beginning to the end of the recognition process.
Use the UIPanGestureRecognizer
class:
-(void)viewDidLoad{[superviewDidLoad];self.view.backgroundColor=[UIColorwhiteColor];/* Let's first create a label */CGRectlabelFrame=CGRectMake(0.0f,/* X */0.0f,/* Y */150.0f,/* Width */100.0f);/* Height */self.helloWorldLabel=[[UILabelalloc]initWithFrame:labelFrame];self.helloWorldLabel.text=@"Hello World";self.helloWorldLabel.backgroundColor=[UIColorblackColor];self.helloWorldLabel.textColor=[UIColorwhiteColor];self.helloWorldLabel.textAlignment=UITextAlignmentCenter;/* Make sure to enable user interaction; otherwise, tap eventswon't be caught on this label */self.helloWorldLabel.userInteractionEnabled=YES;/* And now make sure this label gets displayed on the view */[self.viewaddSubview:self.helloWorldLabel];/* Create the Pan Gesture Recognizer */self.panGestureRecognizer=[[UIPanGestureRecognizeralloc]initWithTarget:selfaction:@selector(handlePanGestures:)];/* At least and at most we need only one finger to activatethe pan gesture recognizer */self.panGestureRecognizer ...
Read now
Unlock full access