Reputation: 1964
I am trying to present a new view controller from Left Side with Transition. Here is the Code.
@IBAction func presentNewVC(_ sender: Any) {
let storyBoard = UIStoryboard(name: "Main", bundle: Bundle.main)
let leftMenuController:NewViewController = storyBoard.instantiateViewController(withIdentifier: "NewViewController") as! NewViewController
leftMenuController.modalPresentationStyle = UIModalPresentationStyle.overCurrentContext
leftMenuController.providesPresentationContextTransitionStyle = true
leftMenuController.definesPresentationContext = false
let transition = CATransition()
transition.duration = 1.0
transition.type = kCATransitionMoveIn
transition.subtype = kCATransitionFromLeft
transition.fillMode = kCAFillModeRemoved
view.window!.layer.add(transition, forKey: kCATransition)
present(leftMenuController, animated: false, completion: nil)
}
Now while sliding Animation is being performed while transition the existing view in background also appears to be sliding.
Ideally the transparent new view controller should appear to move from left to right but it also shows existing view as it's background while moving.
Edit: Just to bring more clarity: It's not How to Navigate from Left to Right I am looking for. The Transition is achieved & working fine. The Issue is different. As my Left Menu View is transparent, while presenting it from left to right it also shows underlying existing view as it's own background while transition. Please refer the screenshots & Video. Just want to stop this while transition. Only left transparent view being presented should move from left to right. Please refer Video & Screenshot for more details.
Click here to watch video to understand the issue
Upvotes: 1
Views: 686
Reputation: 587
Here is something I've been using for left to right transition, is this what you are looking for?
class SegueFromLeft: UIStoryboardSegue {
override func perform()
{
let src = self.source
let dst = self.destination
src.view.superview?.insertSubview(dst.view, aboveSubview: src.view)
dst.view.transform = CGAffineTransform(translationX: -src.view.frame.size.width, y: 0)
UIView.animate(withDuration: 0.25,
delay: 0.0,
options: UIViewAnimationOptions.curveEaseInOut,
animations: {
dst.view.transform = CGAffineTransform(translationX: 0, y: 0)
},
completion: { finished in
src.present(dst, animated: false, completion: nil)
}
)
}
}
Upvotes: 1