Advertisement
Guest User

Untitled

a guest
Jan 24th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. import UIKit
  2.  
  3. class ViewController: UIViewController {
  4. override func viewDidLoad() {
  5. super.viewDidLoad()
  6.  
  7. //左スワイプ検知
  8. let leftSwipe = UISwipeGestureRecognizer(target: self, action: #selector(ViewController.swipeGesture(_:)))
  9. leftSwipe.direction = .left
  10. self.view.addGestureRecognizer(leftSwipe)
  11.  
  12. //右スワイプ検知
  13. let rightSwipe = UISwipeGestureRecognizer(target: self, action: #selector(ViewController.swipeGesture(_:)))
  14. rightSwipe.direction = .right
  15. self.view.addGestureRecognizer(rightSwipe)
  16. }
  17.  
  18. //スワイプ検知時の動作
  19. func swipeGesture(_ sender: UISwipeGestureRecognizer){
  20. //左スワイプの動作
  21. if sender.direction == .left {
  22. //遷移先画面の紐付け(※"NextView"はStoryboardにて設定した画面IDを記述)
  23. let Swipe = self.storyboard!.instantiateViewController(withIdentifier: "NextView")
  24.  
  25. //画面遷移処理
  26. self.present( Swipe, animated: true, completion: nil)
  27. print("left")
  28. }
  29.  
  30. if sender.direction == .right{
  31. //遷移先画面の紐付け(※"PreviousView"はStoryboardにて設定した画面IDを記述)
  32. let Swipe = self.storyboard!.instantiateViewController(withIdentifier: "PreviousView")
  33.  
  34. //画面遷移処理
  35. self.present( Swipe, animated: true, completion: nil)
  36. print("right")
  37. }
  38. }
  39.  
  40. override func didReceiveMemoryWarning() {
  41. super.didReceiveMemoryWarning()
  42. // Dispose of any resources that can be recreated.
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement