I'm sorry for being such a beginner. I have watched a number of UIGestureRecognizer tutorials and seen some very helpful answers on SO, but making this unique combo of gestures work is evading me. Here are the details. Thanks in advance for the help!
FooViewController, with its own .xib in interface builder, fits into this hierarchy in iOS7:
UIPopover
>> PageViewController
>> FooViewController
>> View (built in .xib)
>> scrollView (just a UIScrollView)
>> DrawingView (a UIView subclass that has touch drawing capabilities)
It also is sometimes replaced by a subclass, we'll call it FooViewControllerSubclass : FooViewController
. These are the gestures I am creating:
- When using FooViewControllerSubclass in place of FooViewController, UIPopover should receive pinch gestures, causing it to dismiss. Else, it doesn't have to worry about pinches.
- scrollView should receive twoFingerPan gestures, causing it to scroll.
- DrawingView should receive all remaining oneFingerGestures, causing it to draw.
Currently, 1 and 3 work great. But for 2, twoFingerPanning simply calls 1's pinch action. If I comment out that pinch action, then twoFingerPanning just results in 3's oneFinger drawing actions on the DrawingView. A summary of the code is here:
@implementation FooViewController
- (id)init
{
self = [super init];
[[NSBundle mainBundle] loadNibNamed:@"FooViewController" owner:self options:nil];
if (self) {
UIPanGestureRecognizer *panGR = self.scrollView.panGestureRecognizer;
panGR.minimumNumberOfTouches = 2;
}
@end
@implementation FooViewControllerSubclass
- (id)init
{
self = [super initWithWb:wb];
if (self) {
UIPinchGestureRecognizer *pinchRecognizer = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(twoFingerPinch:)];
[[self view] addGestureRecognizer:pinchRecognizer];
}
return self;
}
...
- (void)twoFingerPinch:(UIPinchGestureRecognizer *)recognizer
{
if ([[[self nextResponder] nextResponder] isKindOfClass:([PageViewController class])]) {
[[(PageViewController*)[[self nextResponder] nextResponder] popover] dismissPopoverAnimated:YES];
}
}
@end
@implementation DrawingView
{
...
- (void)drawRect:(CGRect)rect{
//Does a bunch of basic drawing stuff using touchesBegan, touchesMoved, etc.
}
}
@end
As a sidenote: I'm also curious whether that whole [[self nextResponder] nextResponder]
part is whatsoever kosher (because it works), and if not how I should be passing that info up the hierarchy.
Thanks!
Have you tried requiring your pan gesture recogniser to fail in order for your pinch gesture recogniser to succeed?
(In iOS 7 you can do this with
UIGestureRecognizerDelegate
methods; in iOS 6 and lower, you need to subclass your pinch gesture recogniser to override-requireGestureRecognizerToFail:
.)