iOS viewWillTransitionToSize - suggested reworking

Hi Jules and team,

Here is my suggested trivial reworking of viewWillTransitionToSize, which allows the app resizing code to happen after rotation has occurred, rather than before rotation has occurred; which helps my own app with all sorts of issues (e.g. where I deal with the iPhone X notch etc.)

- (void) viewWillTransitionToSize: (CGSize) size withTransitionCoordinator: (id<UIViewControllerTransitionCoordinator>) coordinator
{
  [super viewWillTransitionToSize: size withTransitionCoordinator: coordinator];


  [coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext>  _Nonnull context) {
    // Nothing to do for this completion
  } completion:^(id<UIViewControllerTransitionCoordinatorContext>  _Nonnull context) {

    // The resize has fully completed. Respond to it!
    sendScreenBoundsUpdate (self);

    // On some devices the screen-size isn't yet updated at this point, so also trigger another
    // async update to double-check..
    MessageManager::callAsync ([=] { sendScreenBoundsUpdate (self); });
  }];

}

BTW Iā€™m not sure that the // On some devices ā€¦ code is actually required with this change.

Anyhow - hoping this helps.

Pete

1 Like