我在原始的,允许的LandscapeRight和LandscapeLeft中将方向设置为AutoRotation。
Screen.orientation = ScreenOrientation.Portrait
Screen.orientation = ScreenOrientation.AutoRotation
当我将Screen.orientation更改为纵向并恢复为自动旋转时,屏幕将保持纵向,直到我旋转手机。
这个问题只发生在android设备上。
发布于 2016-09-23 12:20:41
你不认为这是一种自然行为吗?您设置的方向为纵向,手机转到纵向,然后您更改为自动旋转,现在这将改变方向根据您手中的设备。它不会强制应用程序转到允许的方向进行自动旋转。它将停留在那里,除非你旋转它。如果希望立即更改方向,则需要将方向显式设置为特定值。Read More
希望这能有所帮助
发布于 2016-09-23 14:30:46
这是你应该做的:
1.Change to肖像。
2.When你决定改回AutoRotation,就这么做。
3.Read the current orientation(DeviceOrientation
)。将其转换为ScreenOrientation
,然后将其分配给屏幕方向。
注意::您不应该使用Screen.orientation
读取当前屏幕方向。这是通过Input.deviceOrientation
完成的。
这三个步骤放在代码中:
Screen.orientation = ScreenOrientation.Portrait;
Screen.orientation = ScreenOrientation.AutoRotation;
Screen.orientation = DeviceToScreenOrientation(Input.deviceOrientation);
将Input.deviceOrientation
/DeviceOrientation
枚举转换为Screen.orientation
/ScreenOrientation
枚举的DeviceToScreenOrientation
函数。
ScreenOrientation DeviceToScreenOrientation(DeviceOrientation dvceOr)
{
ScreenOrientation scrOr = ScreenOrientation.Unknown;
switch (dvceOr)
{
case DeviceOrientation.Unknown:
scrOr = ScreenOrientation.Unknown;
break;
case DeviceOrientation.Portrait:
scrOr = ScreenOrientation.Portrait;
break;
case DeviceOrientation.PortraitUpsideDown:
scrOr = ScreenOrientation.PortraitUpsideDown;
break;
case DeviceOrientation.LandscapeLeft:
scrOr = ScreenOrientation.LandscapeLeft;
break;
case DeviceOrientation.LandscapeRight:
scrOr = ScreenOrientation.LandscapeRight;
break;
//Don't know What Enum to use. Implement to match your need
case DeviceOrientation.FaceUp:
//scrOr = ?
break;
case DeviceOrientation.FaceDown:
//scrOr = ?
break;
}
return scrOr;
}
您可能需要切换step #2和#3。
https://stackoverflow.com/questions/39660362
复制相似问题