1
votes

I am attempting to cross-dissolve between two view controllers with a custom segue, the segue initiates properly and performs the animation as intended - however when in landscape mode the destination view controller appears in its portrait layout for the duration of the animation. Once the animation completes the destination view controller "snaps" to its landscape layout. Both of the view controllers are set up using auto layout.

Below is my custom segue's "perform" method:

- (void)perform
{
  UIViewController *srcController = self.sourceViewController;
  UIViewController *dstController = self.destinationViewController;
  dstController.view.transform = srcController.view.transform;

  [UIView transitionFromView:srcController.view 
                      toView:dstController.view 
                    duration:self.animationDuration 
                     options:self.animationOptions 
                  completion:self.animationCompletionBlock];
}

Is it necessary to manually tell the destination view controller to trigger autolayout before it is displayed? And if so how would this be performed? Using the built-in segue with a cross-dissolve does not appear to encounter this problem, I have attempted (without success) to determine what it is doing that my custom segue is not.

This has had me stumped for a while, any help would be appreciated and please let me know if more details are needed.

1

1 Answers

2
votes

So it turns out that the solution to this problem was more simple than I would have imagined. Adding the following line ensures the destination view controller has the right bounds when it lays out its elements:

dstController.view.bounds = srcController.view.bounds;

So the rest of the code becomes:

- (void)perform
{
  UIViewController *srcController = self.sourceViewController;
  UIViewController *dstController = self.destinationViewController;
  dstController.view.transform = srcController.view.transform;
  dstController.view.bounds = srcController.view.bounds;

  [UIView transitionFromView:srcController.view 
                      toView:dstController.view 
                    duration:self.animationDuration 
                     options:self.animationOptions 
                  completion:self.animationCompletionBlock];
}