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/04/02 18:19:40 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-479130967
 
 
   @tobeee I placed the code in an extension of `MainViewController` I attached the file below.
   
   ```
   import Foundation
   import WebKit
   
   extension MainViewController {
       
       override open func viewDidLoad() {
           super.viewDidLoad()
           /**
            * observer notification when keyboard will hide
            */
           NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide), name:UIResponder.keyboardWillHideNotification, object: nil)
       }
   
       
       // There is a bug in WebKit that won't reset the contentOffset after the keyboard has been hidden. This would
       // result in a black (former white) space where the keyboard was located. By manually moving down the content of the
       // scrollView we work around that issue and everything works as usual
       @objc fileprivate 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