Swipe between dispatchers

I am trying to create doilies in the background. I have three different background colors. I made a button and when I click the button my background changes to the next scene. I want to change this and I want to swipe left or right to change the background and not click on the button. How can I achieve this.

here are some more details

my view controller

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.
    }


}

      

enter image description here

+3


source to share


2 answers


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)
}

      

+6


source


Ok I figured it out. The gesture was scrolled in the right pane of Xcode and it was the same as the button in the view. The only difference is that it is displayed on top and not inside the view. So after I realized it was as easy as holding down the ctrl button and dragging it into another view and it worked. Below are some images for some people if they stumble upon this:

enter image description here



enter image description here

+4


source







All Articles