【发布时间】:2016-09-02 20:37:04
【问题描述】:
我正在寻找一种从位于另一个 ViewController 之上的清晰 ViewController 传递触摸的方法。我已经看到了以下帖子:
How to ignore touch events and pass them to another subview's UIControl objects?
我按照他们的提示进行操作,但不幸的是无法正常工作。
我从上到下得到如下视图结构:
VideoViewController (note: clear ViewController can see the buttons underneath)
| passThroughView (note: UIView that is using the PassThroughView subclass)
| collectionView
CameraViewController
| controlContainer
| | recordButton
当在collectionview 外部和passThroughView 后面的recordbutton 上点击时,它应该执行一个新记录。问题是使用以下代码我无法做到这一点:
class PassThroughView: UIView {
override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
let hitView = super.hitTest(point, with: event)!
let cameraVC = CameraViewController()
if hitView == self {
return cameraVC.recordButton
}
return hitView
}
}
一旦我的 passThroughView 被点击,我会在 if 语句中打印,但它不会将我的触摸返回到其他 ViewControllers 按钮。
那么我在这里做错了什么?
【问题讨论】:
标签: ios swift uiviewcontroller touch