1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {

for touch:AnyObject in touches {
let t:UITouch = touch as! UITouch
//检测当前触摸的view是否是textField
if t.view == pwdField || t.view == pwdField || t.view == phoneField{
t.view?.becomeFirstResponder()
}else{
phoneField.resignFirstResponder()
pwdField.resignFirstResponder()
verificationField.resignFirstResponder()
self.resignFirstResponder()
}
}

}

通过响应者链获取对应的第一个符合条件的Responsder

传入响应检测的起点Responsder,一般用于UIView中查找响应者链中的控制器

1
2
3
4
5
6
7
func nextResponder(currentView:UIView)->UIViewController{
var vc:UIResponder = currentView
while vc.isKind(of: UIViewController.self) != true {
vc = vc.next!
}
return vc as! UIViewController
}