如何在不中断的情况下将正在进行的手势从子视图“转移”到超级视图?

时间:2013-11-07 22:08:22

标签: ios objective-c uiwebview uiscrollview uigesturerecognizer

这就是我想要做的事情:

我想开始识别子视图中的手势,然后,当手指离开子视图时,让超级视图接管并处理手势。那可能吗?

enter image description here

目前,手势开始的视图"胜出"。是否有任何方法可以交出"从一个视图到另一个视图的动作"在飞行中#34;而不会将手指从屏幕上抬起来?

这是一个简单演示的代码:

@implementation SPWKViewController {
    UIView *_innerView;
    UIPanGestureRecognizer *_outerGestureRecognizer;
    UIPanGestureRecognizer *_innerGestureRecognizer;

    UILabel *_label;
}

- (void)loadView
{
    [super loadView];

    self.view.backgroundColor = [UIColor yellowColor];

    _innerView = [[UIView alloc] initWithFrame:CGRectMake(50, 50, self.view.frame.size.width - 100, 200)];
    _innerView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
    _innerView.backgroundColor = [UIColor greenColor];

    _label = [[UILabel alloc] initWithFrame:CGRectMake(0, 300, self.view.frame.size.width, 40)];
    _label.autoresizingMask = UIViewAutoresizingFlexibleWidth;
    _label.textAlignment = NSTextAlignmentCenter;
    _label.backgroundColor = [UIColor clearColor];

    [self.view addSubview:_innerView];
    [self.view addSubview:_label];
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    _outerGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handleGesture:)];
    [self.view addGestureRecognizer:_outerGestureRecognizer];

    _innerGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handleGesture:)];
    [_innerView addGestureRecognizer:_innerGestureRecognizer];
}

- (void)handleGesture:(UIGestureRecognizer *)gestureRecognizer
{
    if (gestureRecognizer.state == UIGestureRecognizerStateChanged) {
        if (gestureRecognizer == _outerGestureRecognizer) {
            _label.text = @"outer";
        } else {
            _label.text = @"inner";
        }
    } else {
        _label.text = @"";
    }
}

@end

一些背景信息:我想解决的实际问题是:我想将UIWebView放在UIScrollView中。当我滚动到UIWebView的底部时,我希望父UIScrollView能够接管"并保持滚动,而不必先将手指从屏幕上抬起。我认为,为了实现这一目标,我需要"交出"从UIWebView到父UIScrollView的手势。

谢谢!

0 个答案:

没有答案