Hello,
I am trying to use a custom renderer derived from PageRenderer to prevent rotation on specific pages in an iOS application. I have my own custom page class, LandscapePage which inherits content page (and that is all), so that my LandscapePageRenderer can be hooked up instead of the default PageRenderer. I attempted implementing the ShouldAutorotateToInterfaceOrientation, GetSupportedInterfaceOrientations, and PreferredInterfaceOrientationForPresentation methods and (tried) to limit the view to only landscape.
My implementation is available below:
public class LandscapePageRenderer : PageRenderer
{
public override bool ShouldAutorotateToInterfaceOrientation(UIInterfaceOrientation toInterfaceOrientation)
{
return toInterfaceOrientation == UIInterfaceOrientation.LandscapeLeft || toInterfaceOrientation == UIInterfaceOrientation.LandscapeRight;
}
public override UIInterfaceOrientationMask GetSupportedInterfaceOrientations()
{
return UIInterfaceOrientationMask.Landscape;
}
public override UIInterfaceOrientation PreferredInterfaceOrientationForPresentation()
{
return UIInterfaceOrientation.LandscapeLeft;
}
public override void WillAnimateRotation(UIInterfaceOrientation toInterfaceOrientation, double duration)
{
base.WillAnimateRotation(toInterfaceOrientation, duration);
}
public override bool ShouldAutorotate()
{
if (this.InterfaceOrientation == UIInterfaceOrientation.LandscapeLeft ||
this.InterfaceOrientation == UIInterfaceOrientation.LandscapeRight)
{
return false;
}
return true;
}
}
The GetSupportedInterfaceOrientations method is called before the page is displayed, but the mask appears to be ignored. I can rotate the simulator in any orientation, and the page still auto rotates. I am clearly missing something. I was under the impression that the PageRenderer was the UIVIewController used for the 'page' and it would be possible to set necessary UIViewController overrides/options in the PageRenderer. Is any of that wrong, and/or do I need to implement this behavior differently? Any feedback would be greatly appreciated!
I am using Xamarin Forms 1.1.0 with the iPad simulator, iOS 6.0 and 7.0.