iOS Question Disable AutoRotate on a single view

Discussion in 'iOS Questions' started by Filippo, Jun 16, 2017.

  1. Filippo

    Filippo Expert Licensed User

  2. Filippo

    Filippo Expert Licensed User

  3. Erel

    Erel Administrator Staff Member Licensed User

    You can control the auto rotation property with this code:
    Code:
    Sub Process_Globals
       
    'These global variables will be declared once when the application starts.
       'Public variables can be accessed from all modules.
       Public App As Application
       
    Public NavControl As NavigationController
       
    Private Page1 As Page
       
    Private Page2 As Page
    End Sub

    Private Sub Application_Start (Nav As NavigationController)
       
    'SetDebugAutoFlushLogs(True) 'Uncomment if program crashes before all logs are printed.
       NavControl = Nav
       Page1.Initialize(
    "Page1")
       Page1.RootPanel.LoadLayout(
    "1")
       NavControl.ShowPage(Page1)
       Page2.Initialize(
    "Page2")
       Page2.RootPanel.Color = 
    Colors.Red
    End Sub

    Sub Page1_Click
       NavControl.ShowPage(Page2)
    End Sub

    Sub Main_ShouldAutoRotate As Boolean
       
    If Page2.Visible = True Then
         
    Return False 'Don't auto rotate if Page2 is visible
       Else
         
    Return True
       
    End If
    End Sub


    #if OBJC
    @end
    @interface UINavigationController (B4IResize)

    @end
    @implementation UINavigationController (B4IResize)
    - (BOOL)shouldAutorotate
    {
      return [(NSNumber*)[B4IObjectWrapper raiseEvent:self :@"_shouldautorotate" :nil] boolValue];
    }

    #End If
    To change the orientation: https://www.b4x.com/android/forum/t...-view-in-portrait-only-app.51391/#post-321845
     
    JordiCP and Daniel Uribe like this.
  4. Filippo

    Filippo Expert Licensed User

    Thank you Erel!
    You saved my life. :)
     
  5. Daniel Uribe

    Daniel Uribe Member Licensed User

    Hi, perfect!!

    If you have another module with another NavigationController (with a slider menu by example) how can i call the event? all the page that are in my start navcontrol respond perfectly, but the others no, still changing of orientation. How can i Avoid autorotacion in another modules?
    Thanks a lot!!!!
     
  6. Erel

    Erel Administrator Staff Member Licensed User

    Main_ShouldAutoRotate (in the main module) should be raised in all cases. Add a Log message to test it.
     
    Daniel Uribe likes this.
  7. Filippo

    Filippo Expert Licensed User

    My life is in danger again! :p
    Since I changed the NavigationController and use a SideMenuController, the Sub Main_ShouldAutoRotate is no longer executed.
    How can I fix the problem?
    Code:
    Sub Process_Globals
        
    'These global variables will be declared once when the application starts.
        'Public variables can be accessed from all modules.
        Public App As Application
        
    Public NavControl As NavigationController
        
    Private Page1 As Page
        
    Private Page2 As Page
        
        
    Private smc As SideMenuController
        
    Private pMenu As Page
    End Sub

    Private Sub Application_Start (Nav As NavigationController)
        NavControl.Initialize(
    "NavControl")
        NavControl.NavigationBarVisible = 
    False
        
        Page1.Initialize(
    "Page1")
        Page1.RootPanel.LoadLayout(
    "frmMainIphone")
        NavControl.ShowPage(Page1)
        Page2.Initialize(
    "Page2")
        Page2.RootPanel.Color = 
    Colors.Red
            
        pMenu.Initialize(
    "lp")
        pMenu.RootPanel.LoadLayout(
    "frmMenu")

        smc.Initialize(pMenu, NavControl, 
    Null)
        App.KeyController = smc
    End Sub

    Sub Page1_Click
        NavControl.ShowPage(Page2)
    End Sub

    Sub Main_ShouldAutoRotate As Boolean
        
    If Page2.Visible = True Then
            
    Return False 'Don't auto rotate if Page2 is visible
        Else
            
    Return True
        
    End If
    End Sub


    #if OBJC
    @end
    @interface UINavigationController (B4IResize)

    @end
    @implementation UINavigationController (B4IResize)
    - (BOOL)shouldAutorotate
    {
      return [(NSNumber*)[B4IObjectWrapper raiseEvent:self :@"_shouldautorotate" :nil] boolValue];
    }

    #End If
     
  8. Erel

    Erel Administrator Staff Member Licensed User

    Please start a new thread for this. The above solution will not work as it is based on a different type of controller.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice