私は、これはこれを処理するための最良の方法であることを確認していないが、experiementingせずに、これが唯一の確実な方法Iのようです知ってる。これにより、クリックを認識し、クリック時に自分自身を削除する非表示のビューが作成されます。
class ThisViewController: UITableViewDelegate, UITableViewDatasource {
var tapView: ClickThroughView?
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(LoginViewController.keyboardWillShow), name: UIKeyboardWillShowNotification, object: nil)
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(LoginViewController.keyboardWillHide), name: UIKeyboardWillHideNotification, object: nil)
}
func keyboardWillShow(notification: NSNotification) {
tapView = ClickThroughView(frame: view.frame)
tapView?.delegate = self
view.addSubview(tapView!)
view.bringSubviewToFront(tapView!)
}
func keyboardWillHide() {
}
deinit {
NSNotificationCenter.defaultCenter().removeObserver(self, name: UIKeyboardWillShowNotification, object: nil)
NSNotificationCenter.defaultCenter().removeObserver(self, name: UIKeyboardWillHideNotification, object: nil)
}
}
extension ThisViewController: HandleViewTapDelegate {
func handleTap() {
//code on tap not on keyboard
view.endEditing(true)
tapView?.removeFromSuperview()
tapView = nil
}
}
protocol HandleViewTapDelegate {
func handleTap()
}
class ClickThroughView: UIView {
var delegate: HandleViewTapDelegate?
override func pointInside(point: CGPoint, withEvent event: UIEvent?) -> Bool {
delegate?.handleTap()
return false
}
}