@@ -103,6 +103,12 @@ @implementation EARenderView
103103@synthesize isKeyboardShown;
104104@synthesize originalRect = originalRect_;
105105
106+ static ax::Rect convertKeyboardRectToViewport (CGRect rect, CGSize viewSize)
107+ {
108+ float flippedY = viewSize.height - rect.origin .y - rect.size .height ;
109+ return ax::Rect (rect.origin .x , flippedY, rect.size .width , rect.size .height );
110+ }
111+
106112+ (Class )layerClass
107113{
108114#if defined(AX_USE_METAL)
@@ -661,12 +667,14 @@ - (void)onUIKeyboardNotification:(NSNotification*)notif
661667 auto renderView = ax::Director::getInstance ()->getRenderView ();
662668 float scaleX = renderView->getScaleX ();
663669 float scaleY = renderView->getScaleY ();
670+
671+ const auto backingScaleFactor = self.contentScaleFactor ;
664672
665673 // Convert to pixel coordinates
666674 begin = CGRectApplyAffineTransform (begin,
667- CGAffineTransformScale (CGAffineTransformIdentity, self. contentScaleFactor , self. contentScaleFactor ));
675+ CGAffineTransformScale (CGAffineTransformIdentity, backingScaleFactor, backingScaleFactor ));
668676 end = CGRectApplyAffineTransform (end,
669- CGAffineTransformScale (CGAffineTransformIdentity, self. contentScaleFactor , self. contentScaleFactor ));
677+ CGAffineTransformScale (CGAffineTransformIdentity, backingScaleFactor, backingScaleFactor ));
670678
671679 // Adjust for viewport offset if needed
672680 float offestY = renderView->getViewPortRect ().origin .y ;
@@ -684,19 +692,19 @@ - (void)onUIKeyboardNotification:(NSNotification*)notif
684692 CGAffineTransformScale (CGAffineTransformIdentity, 1 .0f / scaleX, 1 .0f / scaleY));
685693
686694 // Fill notification info for Axmol IME dispatcher
695+ auto winSize = originalRect_.size ;
696+ CGSize viewSize = CGSizeMake (winSize.width * backingScaleFactor / scaleX,
697+ winSize.height * backingScaleFactor / scaleY);
698+
687699 ax::IMEKeyboardNotificationInfo notiInfo;
688- notiInfo.begin = ax::Rect (begin. origin . x , begin. origin . y , begin. size . width , begin. size . height );
689- notiInfo.end = ax::Rect (end. origin . x , end. origin . y , end. size . width , end. size . height );
690- notiInfo.duration = ( float ) aniDuration;
700+ notiInfo.begin = convertKeyboardRectToViewport (begin, viewSize );
701+ notiInfo.end = convertKeyboardRectToViewport (end, viewSize );
702+ notiInfo.duration = aniDuration;
691703
692704 ax::IMEDispatcher* dispatcher = ax::IMEDispatcher::sharedDispatcher ();
693705 if (UIKeyboardWillShowNotification == type)
694706 {
695707 dispatcher->dispatchKeyboardWillShow (notiInfo);
696-
697- // Move the whole render view up by keyboard height
698- CGFloat distance = end.size .height ;
699- [self doAnimationWhenKeyboardMoveWithDuration: aniDuration distance: distance];
700708 }
701709 else if (UIKeyboardDidShowNotification == type)
702710 {
@@ -706,9 +714,6 @@ - (void)onUIKeyboardNotification:(NSNotification*)notif
706714 else if (UIKeyboardWillHideNotification == type)
707715 {
708716 dispatcher->dispatchKeyboardWillHide (notiInfo);
709-
710- // Restore to original rect
711- [self doAnimationWhenKeyboardMoveWithDuration: aniDuration distance: 0 .0f ];
712717 }
713718 else if (UIKeyboardDidHideNotification == type)
714719 {
0 commit comments