27
18

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[Swift] resignFirstResponder 以外でキーボードを隠す

Posted at

表示しているキーボードを隠すとき resignFirstResponder 使いますよね。

ただ 1つの ViewController に複数の textField があったりする場合、resignFirstResponder を使うと隠すのが面倒です。

   textFieldA.resignFirstResponder()
   textFieldB.resignFirstResponder()
   textFieldC.resignFirstResponder()

1つのメソッドをキーボードを隠す

endEditing(Bool) を使うとどの UITextFiled がフォーカスされてるかを気にせずキーボードを隠すことができました。

   view.endEditing(true)

※view は ViewController の view

こちらのほうが楽ですね。

27
18
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
27
18

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?