简体   繁体   中英

Swipe gesture between view controllers

I am trying to create a swipe on background. I have three different color of backgrounds. I have made a button and when I click my button my background changes to next scene. I want to change this and I want to swipe my thumb left or right to change the background and not to have to click on the button. How would I achieve that.

here are some more details

my view controller is

import UIKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}

在此输入图像描述

Swift version:

Add gesture recognizer:

override func viewDidLoad() {
    super.viewDidLoad()
    let recognizer: UISwipeGestureRecognizer = UISwipeGestureRecognizer(target: self, action: "swipeLeft:")
    recognizer.direction = .Left
    self.view .addGestureRecognizer(recognizer)
}

action function:

func swipeLeft(recognizer : UISwipeGestureRecognizer) {
    self.performSegueWithIdentifier("MySegue", sender: self)
}

Ok, So I figured it out. Xcode has swipe gesture in its right panel and it was as same as dropping the button in the view. Only difference is that it shows up on the top instead of inside the view. So after I figured that it was as easy as holding the ctrl button and dragging it to another view and voilla it worked. Below are some images for some people if they stumble upon this:

在此输入图像描述

在此输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM