From 616e16a6855161693a8f30af085f37e06d5e9d67 Mon Sep 17 00:00:00 2001 From: Maximo Piva Date: Thu, 12 May 2016 07:22:11 -0300 Subject: Forward Orientation Methods in PlatformRenderer and ModalWrapper (#147) * PlatformRenderer and ModalWrapper are Wrappers around the real UIViewController, rotation and orientations methods are not correctly forwarded in IOS. Per example, you cannot programatically lock the rotation of the IOS screen. This changes will fix that. * Changed spaces to tabs, as requested. --- Xamarin.Forms.Platform.iOS/PlatformRenderer.cs | 71 +++++++++++++++++++++++++- 1 file changed, 69 insertions(+), 2 deletions(-) (limited to 'Xamarin.Forms.Platform.iOS') diff --git a/Xamarin.Forms.Platform.iOS/PlatformRenderer.cs b/Xamarin.Forms.Platform.iOS/PlatformRenderer.cs index 43534b2b..554c0f50 100644 --- a/Xamarin.Forms.Platform.iOS/PlatformRenderer.cs +++ b/Xamarin.Forms.Platform.iOS/PlatformRenderer.cs @@ -25,9 +25,43 @@ namespace Xamarin.Forms.Platform.iOS public override UIInterfaceOrientationMask GetSupportedInterfaceOrientations() { - return UIInterfaceOrientationMask.All; + if ((ChildViewControllers != null) && (ChildViewControllers.Length > 0)) + { + return ChildViewControllers[0].GetSupportedInterfaceOrientations(); + } + + return base.GetSupportedInterfaceOrientations(); + } + + public override UIInterfaceOrientation PreferredInterfaceOrientationForPresentation() + { + if ((ChildViewControllers != null) && (ChildViewControllers.Length > 0)) + { + return ChildViewControllers[0].PreferredInterfaceOrientationForPresentation(); + } + return base.PreferredInterfaceOrientationForPresentation(); } + public override bool ShouldAutorotate() + { + if ((ChildViewControllers != null) && (ChildViewControllers.Length > 0)) + { + return ChildViewControllers[0].ShouldAutorotate(); + } + return base.ShouldAutorotate(); + } + + public override bool ShouldAutorotateToInterfaceOrientation(UIInterfaceOrientation toInterfaceOrientation) + { + if ((ChildViewControllers != null) && (ChildViewControllers.Length > 0)) + { + return ChildViewControllers[0].ShouldAutorotateToInterfaceOrientation(toInterfaceOrientation); + } + return base.ShouldAutorotateToInterfaceOrientation(toInterfaceOrientation); + } + + public override bool ShouldAutomaticallyForwardRotationMethods => true; + public override void ViewDidLayoutSubviews() { base.ViewDidLayoutSubviews(); @@ -60,9 +94,42 @@ namespace Xamarin.Forms.Platform.iOS public override UIInterfaceOrientationMask GetSupportedInterfaceOrientations() { - return UIInterfaceOrientationMask.All; + if ((ChildViewControllers != null) && (ChildViewControllers.Length > 0)) + { + return ChildViewControllers[0].GetSupportedInterfaceOrientations(); + } + return base.GetSupportedInterfaceOrientations(); } + public override UIInterfaceOrientation PreferredInterfaceOrientationForPresentation() + { + if ((ChildViewControllers != null) && (ChildViewControllers.Length > 0)) + { + return ChildViewControllers[0].PreferredInterfaceOrientationForPresentation(); + } + return base.PreferredInterfaceOrientationForPresentation(); + } + + public override bool ShouldAutorotate() + { + if ((ChildViewControllers != null) && (ChildViewControllers.Length > 0)) + { + return ChildViewControllers[0].ShouldAutorotate(); + } + return base.ShouldAutorotate(); + } + + public override bool ShouldAutorotateToInterfaceOrientation(UIInterfaceOrientation toInterfaceOrientation) + { + if ((ChildViewControllers != null) && (ChildViewControllers.Length > 0)) + { + return ChildViewControllers[0].ShouldAutorotateToInterfaceOrientation(toInterfaceOrientation); + } + return base.ShouldAutorotateToInterfaceOrientation(toInterfaceOrientation); + } + + public override bool ShouldAutomaticallyForwardRotationMethods => true; + public override void ViewDidAppear(bool animated) { Platform.DidAppear(); -- cgit v1.2.3