October 2013
Intermediate to advanced
1053 pages
28h 7m
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];/* 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=NSTextAlignmentCenter;/* 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 our 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.minimumNumberOfTouches=1;self.panGestureRecognizer ...
Read now
Unlock full access