在我的viewController中,我有一个位于UITableView上方的imageSlider。
我想将垂直swipeGesture从imageSlider转发到基础tableview。所以当我在imageSlider上垂直滑动时,底层tableView开始滚动。 (tableview可以在imageSlider下面滚动)
我做了什么:
我为viewController View创建了一个自定义视图,并使用覆盖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?
你的想法是什么?你是如何处理这种困境的?