我正在尝试仅使一个视图控制器锁定为纵向模式,同时允许所有其他视图为任意方向.这就是我试图放入homeViewController(我想保持肖像的那个)的方式.
public override UIInterfaceOrientationMask GetSupportedInterfaceOrientations()
{
return UIInterfaceOrientationMask.Portrait;
}
public override UIInterfaceOrientation PreferredInterfaceOrientationForPresentation()
{
return UIInterfaceOrientation.Portrait;
}
public override bool ShouldAutorotate()
{
return false;
}
我正在尝试在C#中的Xamarin中执行此操作.有人有建议吗?
解决方法:
在AppDelegate.cs中添加
public bool RestrictRotation
{
get;
set;
}
并将其添加到同一AppDelegate.cs中,但在FinishedLaunching()方法之后
[Export("application:supportedInterfaceOrientationsForWindow:")]
public UIInterfaceOrientationMask GetSupportedInterfaceOrientations(UIApplication application, IntPtr
forWindow)
{
if (this.RestrictRotation)
return UIInterfaceOrientationMask.Portrait;
else
return UIInterfaceOrientationMask.All;
}
在想要制作人像的每个ViewController中添加以下内容
public override void ViewDidLoad()
{
base.ViewDidLoad();
this.RestrictRotation(true);
// Perform any additional setup after loading the view, typically from a nib.
}
public override bool ShouldAutorotate()
{
return false;
}
public override UIInterfaceOrientationMask GetSupportedInterfaceOrientations()
{
return UIInterfaceOrientationMask.Portrait;
}
public override UIInterfaceOrientation PreferredInterfaceOrientationForPresentation()
{
return UIInterfaceOrientation.Portrait;
}
void RestrictRotation(bool restriction)
{
AppDelegate app = (AppDelegate)UIApplication.SharedApplication.Delegate;
app.RestrictRotation = restriction;
}