解决方法
Apple在
Responder Chain中解释得非常好.您可以将以下功能添加到视图控制器:
override func touchesEnded(_ touches: Set<UITouch>,with event: UIEvent?) { if let firstTouch = touches.first { let hitView = self.view.hitTest(firstTouch.location(in: self.view),with: event) if hitView === viewB { print("touch is inside") } else { print("touch is outside") } } }