0

I have a custom transition between viewcontrollers that fades the current VC out and the new one in which works great, but on iOS 13 now when the viewcontroller is presented modally with its new transition where you can still see the previous VC in the background, my transition is overriding it, I would like it to keep the gap at the top and the rounded corners instead of becoming fullscreen.

Example of it working the old way (ive slowed the animations down):

enter image description here

how it looks on iOS 13:

enter image description here

this is the code im using to do the transition:

class FadeAnimationController: NSObject, UIViewControllerAnimatedTransitioning {

  func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
    return 3
  }

  func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {

    guard let fromVC = transitionContext.viewController(forKey: .from),
      let toVC = transitionContext.viewController(forKey: .to)
      else {
        return
    }

    let duration = self.transitionDuration(using: transitionContext)

    transitionContext.containerView.backgroundColor = .white
    transitionContext.containerView.addSubview(toVC.view)
    transitionContext.containerView.addSubview(fromVC.view)

    toVC.view.alpha = 0

    UIView.animate(withDuration: duration, animations: {
      toVC.view.alpha = 1
      fromVC.view.alpha = 0
    }, completion: { _ in
      transitionContext.completeTransition(!transitionContext.transitionWasCancelled)
    })
  }
}

the snapshot and the toVC are the ones becomes the full size of the screen instead of remaining the same size and shape of the fromVC. How can I prevent this from happening?

Fonix
  • 11,447
  • 3
  • 45
  • 74

2 Answers2

0

I think your problem is your call:

transitionContext.containerView.addSubview(fromVC.view)

You shouldn't need to do that.

Rob C
  • 4,877
  • 1
  • 11
  • 24
  • I did try take that out initially, but it seems the make the `fromVC` do a weird default transition of its own, it sort of fades out and shrinks, probably something to do with it being presented modally – Fonix Apr 02 '20 at 14:52
  • also leaves a weird gap at the bottom (i took out making the containerView background white, think that is half the problem here) https://imgur.com/a/rMwXjo6 – Fonix Apr 02 '20 at 14:56
  • That's an interesting problem. Let me think about it some more. – Rob C Apr 02 '20 at 14:57
  • @Fonix I think what you're going to need to do is use view controller containment. – Rob C Apr 02 '20 at 15:28
  • so i present like a view controller modally that will contain like a navigation controller that will do all my transitions? – Fonix Apr 02 '20 at 15:38
  • @Fonix Yes, but you'll still need to imple,ent your fade transition – Rob C Apr 02 '20 at 15:40
  • 1
    This [Article](https://developer.apple.com/library/archive/featuredarticles/ViewControllerPGforiPhoneOS/ImplementingaContainerViewController.html) should help you – Rob C Apr 02 '20 at 15:45
0

So turns out I was overriding the wrong type of transition, I should have been overriding the navigation controllers transition and not the view controllers one. So i was effectively creating my own modal presentation transitions instead of the normal show/push animation which is why it was covering the iOS 13 modal transition. I implemented what I found in this answer and it worked well

Fonix
  • 11,447
  • 3
  • 45
  • 74