-1

To me the transition from right to left while opening new view is the most essential part of iPhone UI. How can it be that nearly in 2020 there is no way to have it for transition between two ViewControllers? At least I could not find the way.

Due to reasons I am not using NavigationController in the app. Instead I just call self.present(newVC) to open new one and self.dismiss() to go back.

I just want the new ViewController to slide from the right, that's all.

Any hints?

Arnie Schwarzvogel
  • 825
  • 1
  • 11
  • 24
  • Possible duplicate of [How to present view controller from right to left in iOS using Swift](https://stackoverflow.com/questions/37722323/how-to-present-view-controller-from-right-to-left-in-ios-using-swift) – Kamran Sep 15 '19 at 11:54
  • No it is not. I've read that question and they state in one of answers that this approach is not correct. After some higher iOS version is does not work properly - when you animated, first content of the original VC is displayed, and then after some time the right, new one. This is not acceptable behaviour. – Arnie Schwarzvogel Sep 15 '19 at 12:36
  • Actually there are many answers and the solution is to tweak as per the latest iOS. Best option is [this](https://stackoverflow.com/a/50213557/2395636) that i used after few adjustments. – Kamran Sep 15 '19 at 12:42

2 Answers2

1

It seems you want to slide from right to left.

So you can do it using a custom segue transition. First Create CATransition extenstion than add layer to your segue .


func rightToLeft() -> CATransition {
    self.duration = 0.1 //set the duration to whatever you'd like.
    self.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
    self.type = kCATransitionReveal
    self.subtype = kCATransitionFromRight
    return self
   }

}

Implementation :

DispatchQueue.main.async { //make sure all UI updates are on the main thread.
        nav?.view.layer.add(CATransition().rightToLeft(), forKey: nil)
        nav?.pushViewController(YourViewController(), animated: false)
    }
Ekramul Hoque
  • 562
  • 2
  • 11
0

So you want just slide from right to left here is code :

let transition = CATransition()
    transition.duration = 0.3
    transition.type = CATransitionType.push
    transition.subtype = CATransitionSubtype.fromRight
    transition.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeInEaseOut)
    view.window!.layer.add(transition, forKey: kCATransition)

    let presentedVC = self.storyboard!.instantiateViewController(withIdentifier: "PresentingViewController") \\ view Controller identifire in storyboard 
    presentedVC.view.backgroundColor = UIColor.orange

    present(presentedVC, animated: false, completion: nil)

Here is Sample project

Ekramul Hoque
  • 562
  • 2
  • 11
  • Sorry, exactly this code does not work in my case: the transition first animates content of the current VC, then after some seconds switches to the new one. – Arnie Schwarzvogel Sep 15 '19 at 14:30
  • Sorry I see no practical way how to do it. The whole app works like this. I do not see how it would be possible to stripe it down to show effect. – Arnie Schwarzvogel Sep 15 '19 at 14:36