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 Force the keyboard to go away

    Pythonista
    4
    5
    4084
    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.
    • MalphasWats
      MalphasWats last edited by

      Hi,

      I'm making a little application to post photos to my photo blog. For the sake of learning I thought I'd make a little UI to go with it, but I've run into a problem.

      I have made a sheet that has an ImageView at the top, with a button underneath to choose a photo from the camera roll. Below that, there are 3 TextFields for title and other stuff. I was quite proud of myself for creating a delegate class that shifts the whole View up when the text fields receive focus and then back down when they lose it! (I commented this all out to see if this was a problem but it still happens).

      The ImageView, by chance, ends up being about as tall as the space left when the keyboard is visible, and here's where I hit a problem.

      If I start the app, then press one of the text fields, the keyboard pops up. If I then press the 'choose image' button, I see the keyboard slide away as the photo picker slides in, but when I choose a photo, the ImageView updates and the keyboard slides back up but none of the text fields appear to be selected. Because the ImageView is the same size as the space above the keyboard, I can't select any of the other controls and can't dismiss the keyboard.

      Is there a way to programmatically dismiss the keyboard so I could force it to go away when the 'pick photo' button is pressed?

      Thanks

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

        Try putting all of the elements into a ScrollView. That would allow you to manually scroll up and down, and as far as I know ScrollViews automatically pseudo-resize when the keyboard is up, so there won't be any cases of controls getting "stuck" behind the keyboard.

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

          https://omz-forums.appspot.com/pythonista/post/5854599239958528

          end_editing() is the (secret) sauce.

          Note that the keyboard frame modes are heavily bugged in version 1.5 in full screen mode for most rotations. (Anyone know if this was fixed in 1.6?). If you are using panel you should be fine.
          If you need to use full screen for some reason,
          This fixes the relevant conversion methods and keyboard frame methods.

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

            Thanks guys. I'll try the ScrollView approach when I get some time and see where it gets me.

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

              My somewhat clunky solution hides the keyboard on any attempt to scroll:

              class MyScrollViewDelegate(object):
                  def scrollview_did_scroll(self, scrollview):
                      for sv in scrollview.subviews:
                          if hasattr(sv, 'end_editing'):
                              sv.end_editing()
              
              1 Reply Last reply Reply Quote 0
              • First post
                Last post
              Powered by NodeBB Forums | Contributors