February 2012
Intermediate to advanced
872 pages
22h 43m
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 UIPanGestureRecognizerclass:
- (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor = [UIColor whiteColor]; /* Let's first create a label */ CGRect labelFrame = CGRectMake(0.0f, /* X */ 0.0f, /* Y */ 150.0f, /* Width */ 100.0f); /* Height */ self.helloWorldLabel = [[UILabel alloc] initWithFrame:labelFrame]; self.helloWorldLabel.text = @"Hello World"; self.helloWorldLabel.backgroundColor = [UIColor blackColor]; self.helloWorldLabel.textColor = [UIColor whiteColor]; self.helloWorldLabel.textAlignment = UITextAlignmentCenter; /* Make sure to enable user interaction; otherwise, tap events won't be caught on this label */ self.helloWorldLabel.userInteractionEnabled = YES; /* And now make sure this label gets displayed on the view */ [self.view addSubview:self.helloWorldLabel]; /* Create the Pan Gesture Recognizer */ self.panGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePanGestures:)]; /* At least and at most we need only one finger to activate the pan gesture recognizer */ self.panGestureRecognizer.minimumNumberOfTouches ...Read now
Unlock full access