facebook twitter hatena line google mixi email

Ios/swift/左右ジェスチャー

提供: 初心者エンジニアの簡易メモ
移動: 案内検索
class WebViewController: UIViewController {
   override func viewDidLoad() {
       super.viewDidLoad()
       let rightSwipe = UISwipeGestureRecognizer(target: self, action: #selector(self.didSwipe(_:)))
       rightSwipe.direction = .Right
       view.addGestureRecognizer(rightSwipe)
       let leftSwipe = UISwipeGestureRecognizer(target: self, action: #selector(self.didSwipe(_:)))
       leftSwipe.direction = .Left
       view.addGestureRecognizer(leftSwipe)
   }
   final func didSwipe(sender: UISwipeGestureRecognizer) {
       if sender.direction == .Right {
           print("Right")
       }
       else if sender.direction == .Left {
           print("Left")
       }
   }
}

参考:http://qiita.com/kentarohorie/items/71dddd6f2ea96fa00b39