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.


    UI Sheet View, Can you hide the x?

    Pythonista
    5
    8
    5039
    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.
    • techteej
      techteej last edited by

      Is there any way to hide the name bar with the x on the sheet view? Thanks.

      1 Reply Last reply Reply Quote 1
      • omz
        omz last edited by

        View.present has an optional keyword parameter called hide_title_bar (pass True). When you present a view with the title bar hidden, you can dismiss it with a two-finger swipe down gesture.

        1 Reply Last reply Reply Quote 1
        • Sebastian
          Sebastian last edited by

          view.present(style='sheet', hide_title_bar=True)

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

            Thanks!

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

              Is there a way to stop two-finger swipe down gesture from exiting a view with a hidden title bar?

              mikael 2 Replies Last reply Reply Quote 0
              • mikael
                mikael @RoninSage last edited by

                @RoninSage, this:

                #coding: utf-8
                from ui import *
                from objc_util import *
                
                UILayoutContainerView = ObjCClass('UILayoutContainerView')
                UISwipeGestureRecognizer = ObjCClass('UISwipeGestureRecognizer')
                
                def disable_swipe_to_close(view):
                  v = view.objc_instance
                  while not v.isKindOfClass_(UILayoutContainerView.ptr):
                    v = v.superview()
                  for gr in v.gestureRecognizers():
                    if gr.isKindOfClass_(UISwipeGestureRecognizer.ptr):
                      gr.setEnabled(False)
                
                if __name__ == '__main__':
                  bg = Button(title='Click me')
                  bg.present('fullscreen', hide_title_bar=True)
                  disable_swipe_to_close(bg)
                
                1 Reply Last reply Reply Quote 1
                • mikael
                  mikael @RoninSage last edited by

                  @RoninSage, there’s of course also an option of replacing the two-finger swipe with some other gesture.

                  1 Reply Last reply Reply Quote 1
                  • RoninSage
                    RoninSage last edited by RoninSage

                    @mikael perfect, that does exactly what I wanted. Combined with guided access mode on the iPad, once the python program starts to run the user shouldn’t be able to leave the view at all.

                    But if anyone wants to use this code, I have edited the button function so it will eventually let you out, unfortunately I am not as elegant as @mikael

                    Cheers

                    #coding: utf-8
                    import ui, random
                    from ui import *
                    from objc_util import *
                    
                    
                    def button_tapped(sender):
                      rn=random.random()
                      if rn <0.8:
                        sender.title = 'unlucky, click again to close'
                        button.size_to_fit
                      else:
                        view.close()
                    
                    UILayoutContainerView = ObjCClass('UILayoutContainerView')
                    UISwipeGestureRecognizer = ObjCClass('UISwipeGestureRecognizer')
                    
                    def disable_swipe_to_close(view):
                      v = view.objc_instance
                      while not v.isKindOfClass_(UILayoutContainerView.ptr):
                        v = v.superview()
                      for gr in v.gestureRecognizers():
                        if gr.isKindOfClass_(UISwipeGestureRecognizer.ptr):
                          gr.setEnabled(False)
                    
                    view = ui.View()
                    view.background_color = (0.3,0.31,0.32)
                    button = ui.Button(title='Click this button to close view')
                    button.center = (view.width * 0.5, view.height * 0.5)
                    button.flex = 'LRTB'
                    button.action = button_tapped
                    view.add_subview(button)
                    view.present('fullscreen', hide_title_bar=True)
                    disable_swipe_to_close(view)
                    
                    
                    1 Reply Last reply Reply Quote 0
                    • First post
                      Last post
                    Powered by NodeBB Forums | Contributors