我最初將方向設置爲AutoRotation,允許LandscapeRight和LandscapeLeft。在android中更改方向
Screen.orientation = ScreenOrientation.Portrait
Screen.orientation = ScreenOrientation.AutoRotation
當我改變Screen.orientation爲縱向,恢復到自動旋轉,屏幕保持肖像,直到我輪換了電話。
這個問題只發生在Android設備上。
我最初將方向設置爲AutoRotation,允許LandscapeRight和LandscapeLeft。在android中更改方向
Screen.orientation = ScreenOrientation.Portrait
Screen.orientation = ScreenOrientation.AutoRotation
當我改變Screen.orientation爲縱向,恢復到自動旋轉,屏幕保持肖像,直到我輪換了電話。
這個問題只發生在Android設備上。
難道你不認爲這是自然的行爲?您將方向設置爲縱向,手機進入縱向,然後您更改爲自動旋轉,現在將根據您如何握住設備來改變方向。它不會強制應用程序轉到允許的自定義方向。它會留在那裏,除非你旋轉它。如果您希望立即更改方向,則需要明確將方向設置爲特定值。 Read More
希望這有助於
這是你應該做的:
.Change肖像。
。當您決定更改回自動旋轉時,請執行此操作。
。閱讀當前方向(DeviceOrientation
)。將其轉換爲ScreenOrientation
然後將其分配給屏幕方向。
注:你不應該Screen.orientation
讀取當前屏幕的方向。這是通過Input.deviceOrientation
完成的。
這三個步驟放進代碼:
Screen.orientation = ScreenOrientation.Portrait;
Screen.orientation = ScreenOrientation.AutoRotation;
Screen.orientation = DeviceToScreenOrientation(Input.deviceOrientation);
的DeviceToScreenOrientation
功能轉換Input.deviceOrientation
/DeviceOrientation
枚舉Screen.orientation
/ScreenOrientation
枚舉。
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;
}
您可能需要切換步驟#2和#3。