title: Custom segue won't resize Subview
body: <p>I am using a custom segue for transitioning from a collection view cell to a view controller with a kind of <strong>zoom in/zoom out</strong> style - pretty much like App's do it on the <strong>Homescreen</strong>, when you <strong>open/close</strong> them. </p>
  
  <p>In the destination view controller I am adding one of two child view controller. Navigation to the destination view controller works fine, subviews are added and transformed accordingly. </p>
  
  <p><a href="https://i.stack.imgur.com/Z38LZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Z38LZ.png" alt="enter image description here"></a></p>
  
  <p>Unwinding the segue however results in a mess. The child view seems to snap behind the actual view and disappears as soon as the actual view's navigation is completed.</p>
  
  <p><a href="https://i.stack.imgur.com/HYCwH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/HYCwH.png" alt="enter image description here"></a></p>
  
  <p>Views are added like: </p>
  
  <pre><code>private lazy var documentViewController: DocumentViewController = {
      let storyboard = UIStoryboard(name: "Main", bundle: Bundle.main)
      var viewController = storyboard.instantiateViewController(withIdentifier: "DocumentViewController") as! DocumentViewController
      self.add(asChildViewController: viewController)
      return viewController
  }()
  
  override func viewDidLoad() {
      super.viewDidLoad()
      add(asChildViewController: documentViewController)
  }
  
  private func add(asChildViewController viewController: UIViewController) {
      // Add Child View Controller
      addChildViewController(viewController)
      // Add Child View as Subview
      view.addSubview(viewController.view)
      view.sendSubview(toBack: viewController.view)
      // Configure Child View
      viewController.view.frame = view.bounds
  
      // Notify Child View Controller
      viewController.didMove(toParentViewController: self)
  }
  </code></pre>
  
  <p>These are my segues:</p>
  
  <pre><code>func zoom(_ viewCell: UICollectionViewCell) {
      let toViewController = self.destination
      let fromViewController = self.source
  
      let containerView = fromViewController.view.superview
  
      let cellContentView = viewCell.contentView
      let rect = cellContentView.convert(cellContentView.frame, to: toViewController.view)
      let originalCenter = CGPoint(x: rect.origin.x + rect.size.width / 2, y: rect.origin.y + rect.size.height / 2)
  
      let scaleX = rect.size.width / toViewController.view.frame.width
      let scaleY = rect.size.height / toViewController.view.frame.height
  
      toViewController.view.transform = CGAffineTransform(scaleX: scaleX, y: scaleY)
      toViewController.view.layer.cornerRadius = 50
      toViewController.view.center = originalCenter
  
      containerView?.addSubview(toViewController.view)
  
      UIView.animate(withDuration: 10.5, delay: 0, options: .curveEaseInOut, animations: {
          toViewController.view.transform = CGAffineTransform.identity
          toViewController.view.center = fromViewController.view.center
          toViewController.view.layer.cornerRadius = 0
      }, completion: { success in
          fromViewController.present(toViewController, animated: false, completion: nil)
      })
  }
  
  func unwindZoom(_ viewCell: UICollectionViewCell) {
      let toViewController = self.destination
      let fromViewController = self.source
  
      fromViewController.view.superview?.insertSubview(toViewController.view, at: 0)
  
      UIView.animate(withDuration: 10.5, delay: 0, options: .curveEaseInOut, animations: {
          let cellContentView = viewCell.contentView
          let rect = cellContentView.convert(cellContentView.frame, to: toViewController.view)
          let originalCenter = CGPoint(x: rect.origin.x + rect.size.width / 2, y: rect.origin.y + rect.size.height / 2)
  
          let scaleX = rect.size.width / toViewController.view.frame.width
          let scaleY = rect.size.height / toViewController.view.frame.height
  
          fromViewController.view.transform = CGAffineTransform(scaleX: scaleX, y: scaleY)
          fromViewController.view.center = originalCenter
          fromViewController.view.layer.cornerRadius = 50
      }, completion: { success in
          fromViewController.dismiss(animated: false, completion: nil)
      })
  }
  </code></pre>