I want to change the orientation of the single page. My whole application should be run in portrait but I want to make one page as Landscape/portrait (both).
I have taken reference from below links
http://www.appliedcodelog.com/2017/05/force-landscape-or-portrait-for-single.html
Code is working fine in Android but not in IOS.
AppDelegate.cs
public override UIInterfaceOrientationMask GetSupportedInterfaceOrientations(UIApplication application, [Transient] UIWindow forWindow)
{
var mainPage = Xamarin.Forms.Application.Current.MainPage;
if (mainPage is CartoonDetail_demo2 ||
(mainPage is NavigationPage && ((NavigationPage)mainPage).CurrentPage is CartoonDetail_demo2) ||
(mainPage.Navigation != null && mainPage.Navigation.NavigationStack.LastOrDefault() is CartoonDetail_demo2))
{
return UIInterfaceOrientationMask.All;
}
return UIInterfaceOrientationMask.Portrait;
}
But this condition is never going to be true in any case. Eventually I can not get the page from navigation stack.
So, I use easy way to do the same thing,
I want to make "CartoonDetail_demo2" this page as Landscape/Portrait.
In OnAppearing() method of the "CartoonDetail_demo2" page I have set one flag as true.
And OnDisappering() method of the "CartoonDetail_demo2" page I have set one flag as false.
use this flag in AppDelegate.cs.
public override UIInterfaceOrientationMask GetSupportedInterfaceOrientations(UIApplication application, [Transient] UIWindow forWindow) { if (AppConstants.IsOrientationAll) { return UIInterfaceOrientationMask.All; } return UIInterfaceOrientationMask.Portrait; }
Now, Condition become true whenever I go to the page "CartoonDetail_demo2".
But It is not working and my page is always in Portrait Orientation.
When I simply call this method without any condition then whole application is going in "All" (Landscape/Portrait) orientation.
public override UIInterfaceOrientationMask GetSupportedInterfaceOrientations(UIApplication application, [Transient] UIWindow forWindow) { return UIInterfaceOrientationMask.All; }
By default, My whole application in Portrait Orientation.
I have also tried few other demo but none of are going to working
should I use the plugin Plugin.DeviceOrientation?