问题描述
我正在尝试设计一个视图,其中在水平滚动的 UIPageViewController 之上有一个垂直滚动的 UIScrollView。
从上到下,视图层次如下:
- ShelfView:这是一个清晰的 UIView,它在 UIScrollView 的顶部创建一个空白空间,让用户看到底层的 UIPageViewController
- UIScrollView:具有透明背景的典型 UIScrollView。
- CarouselViewController:包含 UIPageViewController 的 UIViewController 子类
- UIPageViewController:一个典型的 UIPageViewController
作为参考,我提供了布局的屏幕截图。请注意,较大的空白空间被 ShelfView 占据,其背景已设置为 Color.clear。
在 ShelfView 中,我覆盖了 UIView 的 hitTest(_:with:)
方法。这会将 ShelfView 中检测到的所有点击和手势发送到 shelfGestureTarget
,该 view
已设置为 CarouselViewController 的 class ShelfView: UIView {
var shelfGestureTarget: UIView?
/// Sends the hitTest to the target view. If no target view is set,then it will be handled by this view.
override func hitTest(_ point: CGPoint,with event: UIEvent?) -> UIView? {
if (self.point(inside: point,with: event) == false) {
return nil
}
if let shelfGestureTarget = self.shelfGestureTarget {
return shelfGestureTarget
} else {
return self
}
}
}
属性。
view
现在我通过一个简单的 SwipeGestureRecognizer 确认 CarouselViewContoller 的 {{1}} 确实正在接收和识别滑动手势。问题是滑动手势似乎没有向下传播到 UIPageViewController,因此页面在滑动时不会移动。不确定我在这里忽略了什么,所以我真的有一些建议。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)