From 72cbbd97106ba1d05b6f0f10d07daf16516d0929 Mon Sep 17 00:00:00 2001 From: akshayaurora Date: Wed, 25 May 2016 02:37:00 +0530 Subject: [PATCH 1/2] WIP:Initial implementation of keyboard_height, we get correct height. Moving window part is still not tested, fixed. --- recipes/ios/src/ios.pyx | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/recipes/ios/src/ios.pyx b/recipes/ios/src/ios.pyx index 4583320..32e8dc1 100644 --- a/recipes/ios/src/ios.pyx +++ b/recipes/ios/src/ios.pyx @@ -171,3 +171,43 @@ def get_dpi(): '''Return the approximate DPI of the screen ''' return ios_uiscreen_get_dpi() + + +from pyobjus import autoclass, selector, protocol +from pyobjus.protocols import protocols + +NSNotificationCenter = autoclass('NSNotificationCenter') + +protocols["KeyboardDelegates"] = { + 'keyboardWillShow': ('v16@0:4@8', "v32@0:8@16"), + 'keyboardDidHide': ('v16@0:4@8', "v32@0:8@16")} + + +class IOSKeyboard(object): + '''Get listener for keyboard height. + ''' + + kheight = 0 + + def __init__(self, **kwargs): + super(IOSKeyboard, self).__init__() + NSNotificationCenter.defaultCenter().addObserver_selector_name_object_(self, selector("keyboardWillShow"), "UIKeyboardWillShowNotification", None) + NSNotificationCenter.defaultCenter().addObserver_selector_name_object_(self, selector("keyboardDidHide"), "UIKeyboardDidHideNotification", None) + + @protocol('KeyboardDelegates') + def keyboardWillShow(self, notification): + self.kheight = notification.userInfo().objectForKey_( + 'UIKeyboardFrameEndUserInfoKey').CGRectValue().size.height + from kivy.core.window import Window + Window.trigger_keyboard_height() + + @protocol('KeyboardDelegates') + def keyboardDidHide(self, notification): + self.kheight = 0 + from kivy.core.window import Window + Window.trigger_keyboard_height() + +iOSKeyboard = IOSKeyboard() + +def get_kheight(): + return iOSKeyboard.kheight From 2d174322daf115c3efad00b4aeeba3a2441c3120 Mon Sep 17 00:00:00 2001 From: akshayaurora Date: Thu, 26 May 2016 03:09:31 +0530 Subject: [PATCH 2/2] take account device density, for `softinput_mode` --- recipes/ios/src/ios.pyx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/recipes/ios/src/ios.pyx b/recipes/ios/src/ios.pyx index 32e8dc1..05e9831 100644 --- a/recipes/ios/src/ios.pyx +++ b/recipes/ios/src/ios.pyx @@ -196,7 +196,7 @@ class IOSKeyboard(object): @protocol('KeyboardDelegates') def keyboardWillShow(self, notification): - self.kheight = notification.userInfo().objectForKey_( + self.kheight = get_scale() * notification.userInfo().objectForKey_( 'UIKeyboardFrameEndUserInfoKey').CGRectValue().size.height from kivy.core.window import Window Window.trigger_keyboard_height()