iOS Question Portrait mode in all pages except one

Pablo Torres

Active Member
Licensed User
Longtime User
Hi, I have an app that has 5 pages and is in portrait mode only, but ony for one of those pages i need landscape mode to be allowed (it will be up to the user then to rotate or not the device in that page)

Is that posible in B4i?

Need some help please, many thanks
 

Indy

Active Member
Licensed User
Longtime User
Hi

I use the following to override my Portrait only setting in all but one screen in my Android application.

B4X:
Dim p As Phone
p.SetScreenOrientation(-1)

Not sure if it's available in iOS though, so you'll have to try it. I put this code in the Activity_Create.

Thanks
 
Upvote 0

Indy

Active Member
Licensed User
Longtime User
Hold on a sec. I just checked my old iOS project and I don't see that code in there. I do however see something that may do the same. Try the following and see if this works;

B4X:
Private pg As Page ' define in Process_Globals

Sub pg_Resize(Width As Int, Height As Int) 'As String
   Dim orientation As String = ""
   If Width > Height Then
       orientation = "Landscape"
       SetOrientation(True)
   Else
       orientation = "Portrait"
       SetOrientation(False)
   End If
   Log(orientation)   
   'Return orientation
End Sub

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

I used this in an app I was developing for iOS which was a copy of the same in Android. Mainly I used this for the Camera activity so pictures could be taken in both orientations even though the app only functioned in portrait.

Hope this helps. Good luck.
 
Upvote 0

Indy

Active Member
Licensed User
Longtime User
I dont have Resize event in the pages

Sorry, I forgot to mention that the object (the page in this case) needs to be initialised;

B4X:
If pg.IsInitialized = False Then
       pg.Initialize("pg")
End If

This will then give you access to the resize event.

Hope this helps.

Thanks
 
Upvote 0
Top