26
27

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 でキーボードをタッチイベントで隠す

Last updated at Posted at 2015-05-27

UITextField/UITextView などの入力箇所以外でキーボードを「Tap Gesture Recognizer」を利用して隠します。「Tap Gesture Recognizer」はジェスチャーを感知して処理を行う時に使うようです。

Storyboard で必要なViewにTap Gesture Recognizerを配置

xcode.gif

Storyboard で Tap Gesture Recognizer と処理を結びつける

紐づるける処理

AddController.swift
    @IBAction func tapScreen(sender: UITapGestureRecognizer) {
        self.view.endEditing(true)
    }

Xcode の操作

xcode2.gif

結果

  • Sent Acitions に紐付けたswiftファイルの名前?Class名が出ている

環境

  • Xcode 6.3
  • Swift 1.2
  • iOS 8
26
27
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
26
27

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?