3
5

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.

UIScrollViewでtouchesBeganを使えるようにする(キーボートをタッチで閉じる時など)

Posted at

UIScrollViewでtouchesBeganが使えなかったのでメモ

New File...で新しいファイル(名前は自分で決めてください.swift)を作成し、以下をコピペ

import Foundation
import UIKit 

extension UIScrollView {
    public override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
        self.nextResponder()?.touchesBegan(touches, withEvent: event)
    }
}

イベントを処理する側に追加

override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
        //キーボードを閉じる
        self.view.endEditing(true)
    }

参考にしたサイト
http://mzgkworks.hateblo.jp/entry/uitableview-extension

3
5
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
3
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?