UITextField를 입력 한 후 입력 키보드를 닫는 방법
2997 단어 XcodeiOSSwiftStoryboard
1. 키보드 입력 결정
입력용 키보드의 오른쪽 하단 부분을 결정 표기로 한다
아래와 같이 UITextField의 'Return Key'를 'Done'으로 설정

UITextFieldDelegate를 ViewController에 구현
ViewController.swift
class ViewController : UIViewController, UITextFieldDelegate {
@IBOutlet var textField : UITextField!
override func viewDidLoad() {
super.viewDidLoad()
self.textField.delegate = self
}
func textFieldShouldReturn(textField: UITextField) -> Bool {
textField.resignFirstResponder()
return true
}
...
}
포인트는 아래 2점.
위를 구현하면 키보드 입력 결정 버튼을 사용하여 입력 키보드를 숨길 수 있습니다.
2. UITextField 이외의 부분을 터치
또 하나가 UITextField 이외의 부분을 터치했을 경우에 비표시로 하는 방법입니다.
ViewController의 touchesBegan 메소드를 오버라이드(override) 해 이하의 내용을 구현하는 것으로 대응할 수 있습니다.
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
if (self.textField.isFirstResponder()) {
self.textField.resignFirstResponder()
}
}
참고원
Reference
이 문제에 관하여(UITextField를 입력 한 후 입력 키보드를 닫는 방법), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/SRAUFactory/items/7314793bd51e4075a208텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)