5

这就是我想要做的:

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

在此处输入图像描述

目前,手势开始的视图“获胜”。有没有办法在不将手指从屏幕上抬起的情况下“即时”将手势从一个视图“移交”到另一个视图?

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

@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。

谢谢!

4

0 回答 0