danutha
danutha

Reputation: 214

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

Upvotes: 0

Views: 412

Answers (3)

RajeshKumar R
RajeshKumar R

Reputation: 15768

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

Upvotes: 1

PGDev
PGDev

Reputation: 24341

You can also use Custom Transitions for achieving something like this.

Refer to : https://github.com/pgpt10/Custom-Animator on how to implement custom transitioning in a view controller.

Upvotes: 1

chengsam
chengsam

Reputation: 7405

  1. Ensure your ViewController is embedded in a NavigationController.
  2. Ensure you selected Show instead of Present for the segue in storyboard.

Upvotes: 1

Related Questions