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!
Forum Archive
Slide up view when keyboard is present
mcarrara3
Jul 18, 2014 - 12:00
Omega0
Jul 17, 2014 - 20:26
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.
Omega0
Jul 17, 2014 - 20:29
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)
Omega0
Jul 17, 2014 - 20:30
The buffer variable should be however much room you want between the keyboard and the thing you are editing.
mcarrara3
Jul 17, 2014 - 21:04
Thanks a lot! This forum is awesome! I am learning a lot!
Omega0
Jul 17, 2014 - 23:36
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.
mcarrara3
Jul 18, 2014 - 12:00
Thanks!