Xamarin.iOS: how to determinate the statusbar height in ViewWillTransitionToSize

192 views Asked by At

I have have a View containing:

  • a MKMapView, to display some items on a map
  • an UITableView embedded in a UIView, to display the items in a list

The user must be able to display the map or the list, by moving a separator.

This works well, but I encounter an issue after the user rotates the screen: in this case, the list is no longer correctly displayed.

The list's position UIView is setted by specifying it's top margin constraint: the first time I know the status bar height (with UIApplication.SharedApplication.StatusBarFrame.Height).

But after the rotation, I need to recalculate this constraint. For this, I try to recalculate the constraints in ViewWillTransitionToSize().

My problem is that I don't get the expected value during the call to ViewWillTransitionToSize(): the "old" value of StatusBarFrame.Height is setted.

I also try to get the statusbar status with UIApplication.SharedApplication.StatusBarHidden but the problem is the same.

Is there another way allowing me to get the correct statusbar height during the rotation?

1

There are 1 answers

0
Gold.strike On

I've tested the statusbar status at the wrong place:

public override void ViewWillTransitionToSize(CoreGraphics.CGSize toSize, IUIViewControllerTransitionCoordinator coordinator) 
{
    coordinator.AnimateAlongsideTransition((IUIViewControllerTransitionCoordinatorContext obj) => {
        // Define any animations you want to perform (equivilent to willRotateToInterfaceOrientation)
        // StatusBar status and height is not yet updated
    }, (IUIViewControllerTransitionCoordinatorContext obj) => {
        // Completition executed after transistion finishes (equivilent to didRotateFromInterfaceOrientation)
        // StatusBar status and height is well updated
    });

    base.ViewWillTransitionToSize(toSize, coordinator);
}

If the test is dont correctly, this works fine.