Search code examples
iosswiftuisegmentedcontrolswipe-gesture

Swift :Segmented control with a swipe gesture between views


I'm using a UIContainer to switch between views using segmented control + swipe gesture.

My storyboard is like this one.enter image description here

Override func viewDidLoad() {
super.viewDidLoad()

var swipeRight = UISwipeGestureRecognizer(target: self, action: "respondToSwipeGesture:")
swipeRight.direction = UISwipeGestureRecognizerDirection.Right
self.view.addGestureRecognizer(swipeRight)

}

I tired many open resources for Github but it is written in objective-C? Can anyone help


Solution

  • func respondToSwipeGesture(gestureReconizer: UISwipeGestureRecognizer) {
        self.performSegueWithIdentifier("SegueFromFirstScreenToSecond", sender: nil)     
    }
    

    Here is the method you would have to implement if you already have created the segue and named it "SegueFromFirstScreenToSecond". If you have not already made the segue, do not worry! It is as easy as drawing from the first responder of the view in storyboard to the next screen and then setting the identifier to "SegueFromFirstScreenToSecond".

    Best of luck!