Multiple pan gestures in a mixing console app
ios, ipad, iphone, objective-c, uigesturerecognizer
Solution
You can create separate gesture recognizers for each slider, e.g. assuming you had a collection outlet:
- (void)viewDidLoad
{
[super viewDidLoad];
[self.sliders enumerateObjectsUsingBlock:^(UIView *slider, NSUInteger idx, BOOL *stop) {
UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePan:)];
[slider addGestureRecognizer:pan];
}];
}
Then, the gesture recognizer would then handle each one individually (surprisingly, without needing to recognize them simultaneously with `shouldRecognizeSimultaneouslyWithGestureRecognizer`):
- (void)handlePan:(UIPanGestureRecognizer *)gesture
{
CGPoint translation = [gesture translationInView:gesture.view];
gesture.view.transform = CGAffineTransformMakeTranslation(0.0, translation.y);
if (gesture.state == UIGestureRecognizerStateEnded)
{
CGRect frame = gesture.view.frame;
frame.origin.y += translation.y;
gesture.view.frame = frame;
gesture.view.transform = CGAffineTransformIdentity;
}
}
Problem
I would like my iPad mixing console app to be able to move multiple sliders simultaneously when a user touches them with multiple fingers, just like in real life. I have already implemented my logic for a single pan gesture (UIPanGestureRecognizer). How do I add multiple-touch functionality in this case? There is a requirement of iOS 5.1 compatibility. Edit: for reference, here is what the gesture looks like on real-life mixing consoles: