Reputation: 214
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
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
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
Reputation: 7405
Upvotes: 1