0

在我的 viewController 中,我有一个位于 UITableView 上方的 imageSlider。

我想将 imageSlider 中的垂直 swipeGesture 转发到底层的 tableview。所以当我在 imageSlider 上垂直滑动时,底层的 tableView 开始滚动。(tableview可以在imageSlider下方滚动)

在此处输入图像描述

我做了什么:

我为我的 viewController 视图创建了一个自定义视图并具有覆盖hitTest:WithEvent:方法:

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
    UIView *targetView = self.flexibleHeader;
    // Convert the point to the target view's coordinate system.
    // The target view isn't necessarily the immediate subview
    CGPoint pointForTargetView = [targetView convertPoint:point fromView:self];
    if (CGRectContainsPoint(targetView.bounds, pointForTargetView)) {
        // The target view may have its view hierarchy,
        // so call its hitTest method to return the right hit-test view
        UIView *finalView = [targetView hitTest:pointForTargetView withEvent:event];
        //final view should be UIButton or other UIControl element in RestaurantFlexibleHeader view
        if (![finalView isKindOfClass:[targetView class]]) {
            return finalView;
        }
    }
    
    return [super hitTest:point withEvent:event];
}

但问题是我无法从 UIEvent 中检测到滑动手势。因为 allTouches 属性是空的!我可以将 imageSlider 放在 tableView 下面,所以当我开始在 imageSlider 上垂直滚动时 tableView 开始开始滚动。但是如何将水平滑动和点击事件转发到 imageSlider?

那么你的想法是什么?你如何处理这个困境?

4

0 回答 0