3

我目前拥有的:

UIViewController我的main 里面有一个孩子UIViewController。在这个孩子中,UIViewController我有一个UITableView,尽管它里面可以有任何东西(UIScrollView, UIImageView, 不同UIViews子类的组成)。

在我的 mainUIViewController我有GestureRecognizerDelegate,所以我在做出手势时收到回调,如下所示:

- (void)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer movedWithTouches:(NSSet*)touches andEvent:(UIEvent *)event;

- (void)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer endWithTouches:(NSSet*)touches andEvent:(UIEvent *)event;

@optional

- (void)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer beganWithTouches:(NSSet*)touches andEvent:(UIEvent *)event;

对于在 main 之上完成的特定手势UIViewController,我展示了一个UIView带有UIImageView. 因此,基本上,当从顶部到底部进行触摸时,Y < 100 的 UIView 动画并显示图像,当我从屏幕上松开手指时,UIView返回顶部。它很像 Apple 提供的通知中心,只是我不控制它的滚动,它只显示距离顶部 200 像素的区域。

问题:

理论上UIViewwith theUIImage是我的层次结构中最高的UIView,但是当我用手指在它的区域上继续移动时,我可以看到它UITableView下面的移动。对我来说这没有意义,因为UIViewwith theUIImageView应该捕捉这些手势。

我想要的是:

只是当我显示UIView禁用UIImage所有交互时childViewController

我试过的:

目前我有这个:

-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
    return YES;
}

如果我设置为 NO,则UIViewwithUIImage甚至不会显示。

如果我放了类似的东西myChildViewController.view.userInteractionEnabled = NO,因为手势已经开始,所以它不起作用。当然,如果我在手势开始之前使用它,一切都会按预期工作。但问题是我将无法使用UITableView.

4

1 回答 1

1

好吧,最终起作用的是:

   -(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
    // Check if I am not on the Default state (UIView with the UIImageView hidden)
    if(currentState != kDefaultState)
    {
        otherGestureRecognizer.enabled = NO;
        [arrayOfDisabledGestures addObject:otherGestureRecognizer];
    }

    return YES;
}

当我最终关闭UIView时,UIImageView我执行以下操作:

[arrayOfDisabledGestures makeObjectsPerformSelector:@selector(setEnabled:) withObject:@YES];

重新启用所有手势。我真的不喜欢这个解决方案,我认为应该有(而且我打赌有)其他方法可以做到这一点。

于 2013-01-08T07:36:05.103 回答