2

I'm trying to add a custom transition to a UIViewController which has a xib. I have tried a few approaches but they all have the same issue, the view displays for the wrong screen size.

My current example is based on the following tutorial: Custom UIViewController transition in iOS with Swift

I have made no changes to the TransitionDelegate or Animators.

Here's the view in the xib and in the simulator:

UIViewController Loads For Wrong Size

The white UIView is set to centre, 80% width with a 1:1 ratio.

My UIViewController is loaded using the following:

let thirdViewController = ThirdViewController()
    thirdViewController.transitioningDelegate = viewTransitionDelegate
    thirdViewController.modalPresentationStyle = .custom
    navigationController?.present(thirdViewController, animated: true, completion: nil)

If I comment out setting the delegate the view will load 100% perfectly:

UIViewController Loads Correctly Without Transition Delegate

Finally, I have another UIViewController which has no xib and the constraints are set programmatically. This view is loaded with the same transition and loads perfectly:

UIViewController Loads Correctly Without XIB

What do I need to change to get this working with XIBs?

Leon
  • 3,614
  • 1
  • 33
  • 46

1 Answers1

4

I spent ages looking for an answer to this and then found it from one of the related questions in the sidebar.

All I needed to do was add the following to my animator:

toViewController.view.frame = fromViewController.view.frame

I hope this helps someone one day.

Leon
  • 3,614
  • 1
  • 33
  • 46
  • 1
    Amazing!!! Works fine! I tried to use every type of "layout subviews solution", but apparently when using custom transitions, a xib or storyboard file is overwritten. – Pedro Ortiz Jan 27 '20 at 21:59