You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by GitBox <gi...@apache.org> on 2019/03/28 10:18:46 UTC

[GitHub] [cordova-ios] idoodler commented on issue #417: Keyboard Dismissal Leaves Viewport Shifted in iOS 12 / XCode 10

idoodler commented on issue #417: Keyboard Dismissal Leaves Viewport Shifted in iOS 12 / XCode 10
URL: https://github.com/apache/cordova-ios/issues/417#issuecomment-477533972
 
 
   > Hi all, i am facing that issue run on IOS 12 that was built with Xcode 10 (if you build with XCode 9, the issue don't appear). IOS 12 will automatic change content offset of WKScrollview in WKWebview fit with height of keyboard in case keyboardWillShow, but it didn't revert it in case keyboardWillHide. That is my solution to fixed it, hope it help for you.
   > 
   > ```
   > /**
   >  * observer notification when keyboard will hide
   >  */
   > [[NSNotificationCenter defaultCenter] addObserver:self
   >                                                  selector:@selector(keyboardWillHide)
   >                                                      name:UIKeyboardWillHideNotification
   >                                                    object:nil];
   > 
   > /////////////--------------------------//////////////
   > /*
   >  *Description: this method was trigger by selector keyboarwillhide from notification
   >  */
   > -(void)keyboardWillHide
   > {
   >     if (@available(iOS 12.0, *)) {
   >         WKWebView *webview = (WKWebView*)self.webView;
   >          for(UIView* v in webview.subviews){
   >               if([v isKindOfClass:NSClassFromString(@"WKScrollView")]){
   >                       UIScrollView *scrollView = (UIScrollView*)v;
   >                       [scrollView setContentOffset:CGPointMake(0, 0)];
   >               }
   >           }
   >      }
   > }
   > ```
   
   Here is the Swift implementation for anyone wo needs it.
   
   `
   /**
    * observer notification when keyboard will hide
    */
   NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide), name:UIResponder.keyboardWillHideNotification, object: nil)
   
   /*
    *Description: this method was trigger by selector keyboarwillhide from notification
    */
   @objc func keyboardWillHide() {
           if #available(iOS 12, *) {
               webView.subviews.forEach { (subview) in
                   if let scrollView = subview as? UIScrollView {
                       scrollView.setContentOffset(CGPoint(x: 0, y: 0), animated: true)
                   }
               }
           }
       }
   `

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org