iOS Question How to force screen to landscape mode?

watesoft

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: https://www.b4x.com/android/forum/t...cape-view-in-portrait-only-app.51391/#content,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.

B4X:
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
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…