iOS Question How to force screen to landscape mode?


Active Member
Licensed User
Longtime User
My app is restricted to portrait mode only("#iPhoneOrientations: Portrait"), but sometimes I need to temporarily change the screen orientation,My idea is that when a button is clicked, screen changes to landscape, and when it is clicked again, screen changes to portrait.
In b4a, I can use SetScreenOrientation and it works very well.
In b4i, I used the method provided by Erel:,It cannot work unless the Project Attributes is changed to "#iPhoneOrientations: Portrait, LandscapeLeft, LandscapeRight",this is not the result I hope, I hope to be consistent with the Android version,and don’t want the screen to rotate automatically.

Sub SetOrientation(landscape As Boolean)
   Dim no As NativeObject
   Dim value As Int
   If landscape Then value = 4 Else value = 1
   no.Initialize("UIDevice").RunMethod("currentDevice", Null).SetField("orientation", value)
End Sub