Created
June 16, 2015 05:04
-
-
Save dennisroche/4b7c84756f2556d0b024 to your computer and use it in GitHub Desktop.
Attempt at Xamarin Renderer that forces a page to be displayed as Landscape or Portrait. It currently does not work.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class OrientationNavigationRenderer : NavigationRenderer | |
| { | |
| protected override Task<bool> OnPushAsync(Page page, bool animated) | |
| { | |
| if (page is RequestSignaturePadView) | |
| { | |
| var landscapePage = new ForceLandscapeViewController(page); | |
| PushViewController(landscapePage, animated); | |
| return Task.FromResult(true); | |
| } | |
| var portraitPage = new ForcePortraitViewController(page); | |
| PushViewController(portraitPage, animated); | |
| return Task.FromResult(true); | |
| } | |
| private sealed class ForcePortraitViewController : UIViewController | |
| { | |
| public ForcePortraitViewController(Page page) | |
| { | |
| _page = page; | |
| } | |
| public override void ViewDidAppear(bool animated) | |
| { | |
| base.ViewDidAppear(animated); | |
| var view = _page.CreateViewController().View; | |
| Add(view); | |
| } | |
| public override void ViewWillAppear(bool animated) | |
| { | |
| UIApplication.SharedApplication.SetStatusBarOrientation(UIInterfaceOrientation.Portrait, true); | |
| base.ViewWillAppear(animated); | |
| } | |
| public override bool ShouldAutorotate() | |
| { | |
| return false; | |
| } | |
| public override bool ShouldAutorotateToInterfaceOrientation(UIInterfaceOrientation interfaceOrientation) | |
| { | |
| return interfaceOrientation == UIInterfaceOrientation.Portrait || interfaceOrientation == UIInterfaceOrientation.PortraitUpsideDown; | |
| } | |
| public override UIInterfaceOrientationMask GetSupportedInterfaceOrientations() | |
| { | |
| return UIInterfaceOrientationMask.Portrait; | |
| } | |
| private readonly Page _page; | |
| } | |
| private sealed class ForceLandscapeViewController : UIViewController | |
| { | |
| public ForceLandscapeViewController(Page page) | |
| { | |
| _page = page; | |
| } | |
| public override void ViewDidAppear(bool animated) | |
| { | |
| base.ViewDidAppear(animated); | |
| var view = _page.CreateViewController().View; | |
| Add(view); | |
| } | |
| public override void ViewWillAppear(bool animated) | |
| { | |
| UIApplication.SharedApplication.SetStatusBarOrientation(UIInterfaceOrientation.LandscapeLeft, true); | |
| base.ViewWillAppear(animated); | |
| } | |
| public override bool ShouldAutorotate() | |
| { | |
| return true; | |
| } | |
| public override bool ShouldAutorotateToInterfaceOrientation(UIInterfaceOrientation interfaceOrientation) | |
| { | |
| return interfaceOrientation == UIInterfaceOrientation.LandscapeLeft || interfaceOrientation == UIInterfaceOrientation.LandscapeRight; | |
| } | |
| public override UIInterfaceOrientationMask GetSupportedInterfaceOrientations() | |
| { | |
| return UIInterfaceOrientationMask.Landscape; | |
| } | |
| private readonly Page _page; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment