XcodeのTargetからカスタムキーボードを作成しました。
ボタンをタップしキーボードを閉じたいのですが、アプリ内にテキストエリアはありません。
そのためどのホームページを見ても、テキストエリアに関連して閉じている記事ばかりです。
私の場合は、Webviewで表示をしてWebページ上のフォームを入力するときに使用したいです。
その際にキーボードを閉じたいのですがどうしたら良いですか?
resignFirstResponder()
view.endEditing(true)
上記のものは動作しませんでした。
使い方が誤っているのでしょうか?
よろしくお願いします。
swift
1import UIKit 2 3 4class KeyboardViewController: UIInputViewController { 5 @IBOutlet var nextKeyboardButton: UIButton! 6 var calculatorView: UIView! 7 8 9 @IBAction func deleteKey(_ sender: Any) { 10 self.textDocumentProxy.deleteBackward() 11 } 12 13 override func updateViewConstraints() { 14 super.updateViewConstraints() 15 16 // Add custom view sizing constraints here 17 } 18 19 override func viewDidLoad() { 20 super.viewDidLoad() 21 let calculatorNib = UINib(nibName: "KeyboardView", bundle: nil) 22 calculatorView = calculatorNib.instantiate(withOwner: self, options: nil)[0] as? UIView 23 view.addSubview(calculatorView) 24 nextKeyboardButton.addTarget(self, action: #selector(UIInputViewController.advanceToNextInputMode), for: .touchUpInside) 25 26 27 } 28 29 override func didReceiveMemoryWarning() { 30 super.didReceiveMemoryWarning() 31 // Dispose of any resources that can be recreated 32 } 33 34 override func textWillChange(_ textInput: UITextInput?) { 35 // The app is about to change the document's contents. Perform any preparation here. 36 } 37 38 override func textDidChange(_ textInput: UITextInput?) { 39 // The app has just changed the document's contents, the document context has been updated. 40 } 41 @IBAction func buttonNext(sender: AnyObject) { 42 self.advanceToNextInputMode() 43 } 44 45====== 46内容省略 47==== 48 49 50 @IBAction func exitKey(_ sender: Any) { 51 view.endEditing(true) 52 } 53 54} 55
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/12/16 13:20