I'm presenting a UIView over my ViewController which contains a table view that covers the whole view controller. I want to dismiss the UIView when tapping outside of the UIView, but have not found anything that helps the cause. This is what I'm trying to do, and it should work but it's not registering touches even if the UIView is not presented. Anyone dealt with a similar issue?
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
let touch: UITouch? = touches.first
if touch?.view != fullSessionView {
fullSessionView?.removeFromSuperview()
}
}
You should always call
super, like this:But anyway, you want to see if
fullSessionViewcontains the touch. So instead of checking the view where the touch happened, you probably want to check the location of where the touch happened. Something like this: