Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import UIKit
- class ViewController: UIViewController {
- override func viewDidLoad() {
- super.viewDidLoad()
- //左スワイプ検知
- let leftSwipe = UISwipeGestureRecognizer(target: self, action: #selector(ViewController.swipeGesture(_:)))
- leftSwipe.direction = .left
- self.view.addGestureRecognizer(leftSwipe)
- //右スワイプ検知
- let rightSwipe = UISwipeGestureRecognizer(target: self, action: #selector(ViewController.swipeGesture(_:)))
- rightSwipe.direction = .right
- self.view.addGestureRecognizer(rightSwipe)
- }
- //スワイプ検知時の動作
- func swipeGesture(_ sender: UISwipeGestureRecognizer){
- //左スワイプの動作
- if sender.direction == .left {
- //遷移先画面の紐付け(※"NextView"はStoryboardにて設定した画面IDを記述)
- let Swipe = self.storyboard!.instantiateViewController(withIdentifier: "NextView")
- //画面遷移処理
- self.present( Swipe, animated: true, completion: nil)
- print("left")
- }
- if sender.direction == .right{
- //遷移先画面の紐付け(※"PreviousView"はStoryboardにて設定した画面IDを記述)
- let Swipe = self.storyboard!.instantiateViewController(withIdentifier: "PreviousView")
- //画面遷移処理
- self.present( Swipe, animated: true, completion: nil)
- print("right")
- }
- }
- override func didReceiveMemoryWarning() {
- super.didReceiveMemoryWarning()
- // Dispose of any resources that can be recreated.
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement