Search code examples
iosswiftswift3segueuistoryboardsegue

When a segue is called between two UIViewControllers screen needs to slide from right to left


Im working on a project which is done in swift 3 and I calls a segue between two view controllers using the method performSegueWithIdentifier. Though it directs to the desired UIViewController, the screen slides from bottom to top only (by default). My requirement is to make sure the screen slides from right to left once this segue is called. The code is below:

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    if tableView == self.categoryTableView {
        performSegue(withIdentifier: "showBrowsVC", sender: nil)
    }
}

Solution

  • Instead of using performSeguewithIdentifier present viewController with animation like this.

    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    if tableView == self.categoryTableView {
     let transition = CATransition()
     transition.duration = 0.5
     transition.type = kCATransitionPush
     transition.subtype = kCATransitionFromRight
     view.window!.layer.add(transition, forKey: kCATransition)
     let secVC = self.storyboard?.instantiateViewController(withIdentifier: "secViewController") as! secViewController
     secVC.category = home
     present(secVC!, animated: false, completion: nil)
    }
    }
    

    In secViewController.swift you should have a variable which you want to pass values

    class secViewController: UIViewController {
        var category:Bool?
    }