Есть много решений этой проблемы.Я думаю, что UIPresentationController может дать здесь важную подсказку.
Я стараюсь сделать ответ максимально простым здесь.Вы можете изменить параметры или даже создать подкласс UIPresentationController для достижения полной анимации по вашему желанию.
import UIKit
//Green
class TransViewController: UIViewController {
// MARK: - Navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destination.
// Pass the selected object to the new view controller.
let dest = segue.destination
let nextVC = storyboard?.instantiateViewController(withIdentifier: "modelViewController")
if let myPresenter = dest.presentationController{
myPresenter.presentedView!.addSubview(nextVC!.view)
nextVC!.view.center = CGPoint.init(x: nextVC!.view.center.x + nextVC!.view.frame.width , y: nextVC!.view.center.y)
UIView.animate(withDuration: 0.5, animations: {
nextVC!.view.center = self.view.center
}) { (success) in
dest.present(nextVC!, animated: false, completion: nil)
}
}
}
}
//Yellow ; "modelViewController"
class ModelViewController: UIViewController {
@IBAction func click(_ sender : UIButton){
self.dismiss(animated: true, completion: nil)
}
}