2017-05-23 17 views
1

我有一个容器视图,其中包含UIPageViewController的视图。这是在UIViewController里面,占据整个屏幕。在容器视图顶部,我有一个UIView,覆盖了屏幕的一半,其中包含一个按钮和一些文本。我想转发从UIViewUIPageViewController的触动。这样即使用户滑过UIViewUIPageViewController仍可以左/右滑动。我也希望按钮能够被按下,因此不能在UIView上将isUserInteractionEnabled设置为false。向前触摸到UIPageViewController

我该怎么做?

+1

[通过触摸传递到UIViews下方]的可能的复制(https://stackoverflow.com/questions/9026097/passing-through-touches-to-uiviews-underneath) –

回答

1

hitTest是确定谁应该使用触摸/手势的方法。

所以你的“UIView,覆盖一半屏幕”可以从NoTouchHandlerView之类继承。然后这个视图不会消耗触摸。它会通过它来观看它。

class NoTouchHandlerView: UIView 
{ 
    override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? 
    { 
     if let hitTestView = super.hitTest(point, with: event), hitTestView !== self { 
      return hitTestView 
     }else { 
      return nil 
     } 
    } 
} 
+0

这'NoTouchHandlerView'确实有一个'UIButton'虽然,这将禁用'UIButton'? – Tometoyou

+0

@Tometoyou查看更新的答案 – BangOperator