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.
Slide up view when keyboard is present
-
Hello, how can I make the view to 'slide up' when the keyboard appears? I need to insert data into a textfield and this gets covered by the keyboard, making it very difficult to edit. Thanks in advance!
-
I place one of these:
class KeyView (View): ''' A specialty view that when placed inside a ScrollView allows it to slide up automatically when the keyboard is opened ''' def keyboard_frame_will_change(self, frame): x, y, w, h = frame #print frame self.superview.content_inset = (0, 0, h + buffer, 0) return if y < self.superview.height + self.superview.y: self.superview.content_inset = (0, 0, self.superview.height + self.superview.y - y + 6, 0) else: self.superview.content_inset = (0, 0, 0, 0)
inside my ScrollView when I want what you're describing.
It does have to be placed inside a ScrollView though, a normal View won't work. -
Oh, accidentally used a test version of the code. Here' style real one.
class KeyView (View): ''' A specialty view that when placed inside a ScrollView allows it to slide up automatically when the keyboard is opened ''' def keyboard_frame_will_change(self, frame): x, y, w, h = frame #print frame self.superview.content_inset = (0, 0, h + buffer, 0)
-
The buffer variable should be however much room you want between the keyboard and the thing you are editing.
-
Thanks a lot! This forum is awesome! I am learning a lot!
-
Since the ui module is actually based on Apple's own UIKit you can look up some things like this on Apple's development forums but if you do that be prepared for a sea of technical jargon. Here you get an answer quickly from people who actually speak in layman's terms.
-
Thanks!