iOS Question [Solved] Load a different layout when rotated

angel_

Well-Known Member
Licensed User
Longtime User
When I open the new page from the B4XMainPage I load the layout Page1 according to the main being in portrait (Page1_portrait) or landscape (Page1_landscape), but if it is already showing the layout and it is rotated, it does not reload the appropriate layout (Page1_portrait or Page1_landscape) .

I would like one of these options:

- Close the Layout and return to the Main (this is how it works in B4A)
- Reload the correct layout (Page1_portrait or Page1_landscape)

I can't have two variant in the same layout because the data it loads is slightly different
 

Attachments

  • PortraitLandscapeScreens.zip
    5.7 KB · Views: 154

aeric

Expert
Licensed User
Longtime User
B4X:
#Region  Project Attributes
    #ApplicationLabel: Orientation Test
    #Version: 1.0.0
    'Orientation possible values: Portrait, LandscapeLeft, LandscapeRight and PortraitUpsideDown
    #iPhoneOrientations: Portrait, LandscapeLeft, LandscapeRight
    #iPadOrientations: Portrait, LandscapeLeft, LandscapeRight, PortraitUpsideDown
    #Target: iPhone, iPad
    #ATSEnabled: True
    #MinVersion: 8
#End Region

Sub Process_Globals
    Public App As Application
    Public NavControl As NavigationController
    Private Page1 As Page
End Sub

Private Sub Application_Start (Nav As NavigationController)
    NavControl = Nav
    Page1.Initialize("Page1")
    'Page1.RootPanel.LoadLayout("Page1")
    NavControl.ShowPage(Page1)
End Sub

Private Sub Page1_Resize (Width As Int, Height As Int)
    If Width > Height Then
        Page1.RootPanel.RemoveAllViews
        Page1.RootPanel.LoadLayout ("landscape_layout")
    Else
        Page1.RootPanel.RemoveAllViews
        Page1.RootPanel.LoadLayout ("portrait_layout")
    End If
End Sub
 
Upvote 0

angel_

Well-Known Member
Licensed User
Longtime User
It's not what I'm looking for.

The file that I attach makes the first option, I don't know if it's correct.
 

Attachments

  • PortraitLandscapeScreens1.zip
    5.8 KB · Views: 144
Upvote 0

aeric

Expert
Licensed User
Longtime User
If I understand you correctly.
If MainPage in Landscape, once click Button1, Page 1 loads in Landscape. and vice versa.
In Page1, if I rotate the screen, the Page will close.
 

Attachments

  • SeveralScreens.zip
    5.9 KB · Views: 137
Upvote 0

aeric

Expert
Licensed User
Longtime User
If you allow rotate screen in Page1 then change the code in Page 1 to
B4X:
Sub B4XPage_Resize (Width As Int, Height As Int)
    Log("B4XPage1_Resize")
    If Width > Height Then
        Page1_Orientation = "Landscape"
    Else
        Page1_Orientation = "Portrait"
    End If
'    If B4XPages.MainPage.MainPageOrientation <> Page1_Orientation Then
'        B4XPages.ClosePage(Me)
'    Else       
'        LoadPageLayout(Page1_Orientation)
'    End If
    LoadPageLayout(Page1_Orientation)
End Sub
 
Upvote 0

angel_

Well-Known Member
Licensed User
Longtime User
If you allow rotate screen in Page1 then change the code in Page 1 to
B4X:
Sub B4XPage_Resize (Width As Int, Height As Int)
    Log("B4XPage1_Resize")
    If Width > Height Then
        Page1_Orientation = "Landscape"
    Else
        Page1_Orientation = "Portrait"
    End If
'    If B4XPages.MainPage.MainPageOrientation <> Page1_Orientation Then
'        B4XPages.ClosePage(Me)
'    Else      
'        LoadPageLayout(Page1_Orientation)
'    End If
    LoadPageLayout(Page1_Orientation)
End Sub
I try it later, thank you
 
Upvote 0

angel_

Well-Known Member
Licensed User
Longtime User
Why do you need two layout files? It will be much more simple to use a single layout with two variants.
It seemed easier if I had to load the layout according to the size of the screen and orientation
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
It seemed easier if I had to load the layout according to the size of the screen and orientation
It looks weird to me to close the page when the user rotate the screen. It looks like the page hits an error and cannot proceed.
Please explain what you want to achieve so we can give any suggestion.
 
Upvote 0

angel_

Well-Known Member
Licensed User
Longtime User
If you allow rotate screen in Page1 then change the code in Page 1 to
B4X:
Sub B4XPage_Resize (Width As Int, Height As Int)
    Log("B4XPage1_Resize")
    If Width > Height Then
        Page1_Orientation = "Landscape"
    Else
        Page1_Orientation = "Portrait"
    End If
'    If B4XPages.MainPage.MainPageOrientation <> Page1_Orientation Then
'        B4XPages.ClosePage(Me)
'    Else      
'        LoadPageLayout(Page1_Orientation)
'    End If
    LoadPageLayout(Page1_Orientation)
End Sub
It's what I was looking for, thank you
 
Upvote 0
Top