난이이 문제를 해결할 수있는 가장 좋은 방법입니다 확실하지 않다,하지만 experiementing없이,이 유일한 절대 안전한 방법 나는 것 같다 에 대해 알다. 그러면 클릭을 인식하고 클릭시 자체를 삭제하는 보이지 않는보기가 생성됩니다.
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
}
}