我有一个问题,在ISO设置设备的方向。对于iPhone,我想把它锁定到只有肖像模式,但对于iPad,我希望用户能够使用肖像,景观左右。该设置将不会为每个设备保存。
我需要换一种方式吗?

发布于 2019-06-28 18:33:47
使用文本编辑器打开您的info.plist。应该有两个方向部分,您可以定义每个成语的方向,如下所示
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>如果这不能正常工作,您也可以在代码中解决这个问题。在AppDelegate.cs中,尝试重写GetSupportedInterfaceOrientations。
public override UIInterfaceOrientationMask GetSupportedInterfaceOrientations
(
UIApplication application,
[Transient] UIWindow forWindow
)
{
// You will need to figure out how to determine what kind of device you're on. I suggest Xamarin.Essentials, they probably have a service for that.
if (iPhone)
{
return UIInterfaceOrientationMask.Portrait;
}
if (iPad)
{
return UIInterfaceOrientationMask.AllButUpsideDown;
}
return UIInterfaceOrientationMask.All;
}https://stackoverflow.com/questions/56811657
复制相似问题