omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    How to lock landscape orientation? Code view.present(orientations=("landscape",)) does not work anymore

    Pythonista
    7
    11
    5787
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • idchlife
      idchlife last edited by

      I still can rotate my iPad and have portrait orientation. How to disable it?

      Thanks!

      cvp 1 Reply Last reply Reply Quote 0
      • cvp
        cvp @idchlife last edited by cvp

        @idchlife see help of ui.View.present

        The orientations parameter has no effect on iPads starting with iOS 10 
        because it is technically not possible to lock the orientation in an app 
        that supports split-screen multitasking.
        
        1 Reply Last reply Reply Quote 2
        • idchlife
          idchlife last edited by

          Thanks! Wow, that's a bummer. Makes sense, though

          1 Reply Last reply Reply Quote 0
          • JonB
            JonB last edited by

            You can always use the rotation lock hardware switch (or in the bottom settings menu if your hardware button is set to be mute

            1 Reply Last reply Reply Quote 0
            • JonB
              JonB last edited by

              actually, you could detect rotation in layout, then use transform.rotation to manually undo it.

              Drizzel 1 Reply Last reply Reply Quote 0
              • ellie_ff1493
                ellie_ff1493 last edited by

                you might be able to get the gravity vector and flip it back whenever it flips

                1 Reply Last reply Reply Quote 0
                • Drizzel
                  Drizzel @JonB last edited by

                  @JonB I have the same question, though a I have never used these functions before. Can you explain this in a coding statement? I assume it will have to run in the update(self) section?

                  1 Reply Last reply Reply Quote 0
                  • JonB
                    JonB last edited by JonB

                    https://forum.omz-software.com/topic/3115/ui-and-device-rotation-monitoring/2

                    Your root view would be one the custom views above, which implement layout. Then within layout, you can check the orientation using ui.WebView().eval_js('window.orientation') returns 0, 90, 180, or 270. (it's possible the webview needs to be added to a view and visible for this to work, though it can be 1x1)

                    You would then use self.transform=ui.Transform.rotation(angle), and also reset the size to proper w and height, which you will have to swap when it rotations 90 degrees.

                    1 Reply Last reply Reply Quote 0
                    • AddledBadger
                      AddledBadger last edited by

                      Hi,

                      I'd like to lock a view to portrait on the iPhone, and the code below doesn't work to do that, for me.

                      So just to clarify:

                      view.present(orientations = ['portrait'])
                      

                      no longer works?

                      What's the preferred way to lock orientation now? Will the documentation get updated? Once the suggestion above has detected the orientation, how can you lock a Navigation Controller to the correct orientation?

                      Thanks!

                      import ui
                      
                      global FRAME_WIDTH
                      global FRAME_HEIGHT
                      message = 'Blah'
                      
                      def scrollview(message):
                        sv = ui.ScrollView() 
                        sv.background_color = 'blue'
                        FRAME_WIDTH = ui.get_screen_size().width - 2
                        FRAME_HEIGHT = ui.get_screen_size().height - 66 
                        sv.frame = (1, 1, FRAME_WIDTH, FRAME_HEIGHT)     
                        sv.content_size = FRAME_WIDTH, FRAME_HEIGHT + 500 
                        view.add_subview(sv) 
                          
                        tv = ui.TextView()
                        tv.background_color = 'red'
                        tv.frame = (2, 2, FRAME_WIDTH - 4, FRAME_HEIGHT - 4 + 500) 
                        tv.font = ('Palatino', 18)
                        tv.editable = False
                        tv.text = message
                        sv.add_subview(tv)
                      
                      view = ui.View()                                     
                      view.name = 'Demo'                                    
                      view.background_color = 'black'                       
                      view.frame=(0, 0, 400, 400)
                      
                      scrollview(message)
                      
                      view.present(orientations = ['portrait'])
                      
                      
                      mikael 1 Reply Last reply Reply Quote 0
                      • mikael
                        mikael @AddledBadger last edited by

                        @AddledBadger, orientation can still be locked on iPhone, but not with the ”new buggy default” 'sheet' presentation mode - you need to remember to specify 'fullscreen':

                        view.present('fullscreen', orientations=['portrait'])
                        
                        1 Reply Last reply Reply Quote 1
                        • AddledBadger
                          AddledBadger last edited by

                          Superb, thanks, working now.

                          1 Reply Last reply Reply Quote 0
                          • First post
                            Last post
                          Powered by NodeBB Forums | Contributors