我很抱歉成为这样的初学者。我已经观看了一些UIGestureRecognizer教程,并在SO上看到了一些very helpful answers,但是这个独特的手势组合正在躲避我。这是详细信息。在此先感谢您的帮助!
FooViewController在接口构建器中有自己的.xib,适合iOS7中的这个层次结构:
UIPopover
>> PageViewController
>> FooViewController
>> View (built in .xib)
>> scrollView (just a UIScrollView)
>> DrawingView (a UIView subclass that has touch drawing capabilities)
它有时也被子类替换,我们称之为FooViewControllerSubclass : FooViewController
。这些是我正在创建的手势:
目前,1和3 工作得很好。但对于2,2FingerPanning简单地称之为1的捏动作。如果我注释掉那个捏合动作,那么twoFingerPanning只会在DrawingView上产生3个oneFinger绘图动作。代码摘要如下:
@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
作为旁注:我也很好奇整个[[self nextResponder] nextResponder]
部分是否是犹太人(因为它有效),如果不是,我应该如何将这些信息传递给层次结构。
谢谢!
答案 0 :(得分:0)
您是否尝试过要求您的平移手势识别器失败才能使您的捏合手势识别器成功?
(在iOS 7中,您可以使用UIGestureRecognizerDelegate
方法执行此操作;在iOS 6及更低版本中,您需要将您的捏合手势识别器子类化以覆盖-requireGestureRecognizerToFail:
。)