Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MartinZikmund/72c96a266613e5878dbc4ce054804f8e to your computer and use it in GitHub Desktop.
Save MartinZikmund/72c96a266613e5878dbc4ce054804f8e to your computer and use it in GitHub Desktop.
private void InitializeOrientation()
{
_didChangeStatusBarOrientationObserver = NSNotificationCenter
.DefaultCenter
.AddObserver(
UIApplication.DidChangeStatusBarOrientationNotification,
n => {
UpdateCurrentOrientation();
OrientationChanged?.Invoke(this, CurrentOrientation);
}
);
UpdateCurrentOrientation();
}
private void UpdateCurrentOrientation()
{
var currentOrientationMask = UIApplication.SharedApplication
.StatusBarOrientation;
switch (currentOrientationMask)
{
case UIInterfaceOrientation.LandscapeLeft:
CurrentOrientation = DisplayOrientations.LandscapeFlipped;
break;
case UIInterfaceOrientation.LandscapeRight:
CurrentOrientation = DisplayOrientations.Landscape;
break;
case UIInterfaceOrientation.Portrait:
CurrentOrientation = DisplayOrientations.Portrait;
break;
case UIInterfaceOrientation.PortraitUpsideDown:
CurrentOrientation = DisplayOrientations.PortraitFlipped;
break;
}
NativeOrientation = CurrentOrientation;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment