iOS 16 -viewWillTransitionToSize:withTransitionCoordinator: bizarre value in the size parameter ((CGSize) size = (width = 414, height = 394)) on iPhone 14 Pro Max?

I noticed a bug on rotation change in my app on iPhone 14 Pro Max simulator. Basically a view in my view hierarchy is hidden when it shouldn't be. In landscape mode there isn't enough room for this view so I hide it on the iPhone (not essential). But when tilting back to portrait mode I unhide it.

-(void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator

{
    [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
    BOOL isIPhone = UIDevice.currentDevice.userInterfaceIdiom == UIUserInterfaceIdiomPhone;
   BOOL isIPhoneAndGoingLandscapeMode = (isIPhone
                                          && size.width > size.height);

   if (isIPhoneAndGoingLandscapeMode) 
  {
       self.someView.hidden = YES;
  }
  else
  {
       self.someView.hidden = NO;
  }
}

So this view controller is presented modally (form sheet style).

On iPhone 14 Pro Max on orientation -viewWillTransitionToSize:withTransitionCoordinator: is called twice and the size parameter is always:

(CGSize) size = (width = 414, height = 394)

This is the sized passed to my app when rotating to portrait and landscape so my isIPhoneAndGoingLandscapeMode flag always is YES because 414 > 394. The 414 x 394 size appears to be false.

My view controller's view in landscape on iPhone 14 pro max logs out to:

(origin = (x = 0, y = 0), size = (width = 932, height = 430))

And 932 x 430 is the size I expected to be passed to me in -viewWillTransitionToSize:withTransitionCoordinator:

Unless I'm missing something can this behavior be explained?

I opened FB11580679

Potential workaround:

 [coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext>  _Nonnull context)

    {
        UIView *container = context.containerView;
        CGRect containerFrame = container.frame;
        CGSize authenticSize = containerFrame.size; //use the size from the container view to workaround bogus size.

    }

    completion:nil];

Also tried moving this code to -traitCollectionDidChange: but it looks better if the view gets hidden before the rotation, not after.

Heh this weird size is also passed to iPhone 13 Pro Max (even on IOS 15) but I didn't notice before because I also update the hidden property in -viewDidLayoutSubviews if landscape/iPhone combination is detected and on iOS 15 -viewDidLayoutSubviews is called after -viewWillTransitionToSize:withTransitionCoordinator:

What makes this an issue in my app on iOS 16 is UIKit is now making an extra call to -viewWillTransitionToSize:withTransitionCoordinator: after viewDidLayoutSubviews (with the bogus size), so the call to hide the view in -viewWillTransitionToSize:withTransitionCoordinator: ends up winning.

Another potential workaround is to move this code out of -viewWIllTransitionToSize:withTransitionCoordinator and into -viewWillLayoutSubviews OR use -willTransitionToTraitCollection:withTransitionCoordinator:

-(void)willTransitionToTraitCollection:(UITraitCollection*)newCollection withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
{
//iPhone going landscape...translate the size class abstraction into normal terms.
    if (newCollection.userInterfaceIdiom == UIUserInterfaceIdiomPhone
        && newCollection.verticalSizeClass == UIUserInterfaceSizeClassCompact)
    {
         //do it.
    }
    [super willTransitionToTraitCollection:newCollection
                 withTransitionCoordinator:coordinator];
}

Looks like iOS may have stopped passing in the final destination size to -viewWillTransitionToSize:withTransitionCoordinator: in iOS 15, for unknown reasons. This is all from within a view controller presented modally.

iOS 16 -viewWillTransitionToSize:withTransitionCoordinator: bizarre value in the size parameter ((CGSize) size = (width = 414, height = 394)) on iPhone 14 Pro Max?
 
 
Q