需要防止特定视图控制器上的屏幕旋转
我在下面尝试过-
public override bool ShouldAutorotateToInterfaceOrientation(UIInterfaceOrientation toInterfaceOrientation)
{
return false;
}
public override bool ShouldAutorotate()
{
return false;
}
public override UIInterfaceOrientation PreferredInterfaceOrientationForPresentation()
{
return UIInterfaceOrientation.Portrait;
}
public override UIInterfaceOrientationMask GetSupportedInterfaceOrientations()
{
return UIInterfaceOrientationMask.Portrait;
}
什么都没起作用。
提前致谢!
你可以通过这个解释来解决这个问题。
1)在你的AppDelegate中添加一个布尔值例如
public bool disableAllOrientation = false;
2)修改AppDelegate中的UIInterfaceOrientationnMask
public override UIInterfaceOrientationMask GetSupportedInterfaceOrientations(UIApplication application, UIWindow forWindow)
{
if (disableAllOrientation == true)
{
return UIInterfaceOrientationMask.Portrait;
}
return UIInterfaceOrientationMask.All;
}
3)调用要改变方向的视图的控制器
appDelegate.disableAllOrientation = true;
4)当视图关闭或更改时,您需要再次输入布尔值
设置为 false 并仅在需要时才将屏幕置于原始方向。
appDelegate.disableAllOrientation = false;
我希望这能解决您的问题,几天前我也遇到了同样的问题,这对我有帮助。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)