2017-09-28 6 views
0
NotificationCenter.default.addObserver(self, selector: #selector(self.keyboardWillHide), name: NSNotification.Name.UIKeyboardWillShow, object: nil) 

func keyboardWillHide(notification: NSNotification) { 
    if let rect = (notification.userInfo?[UIKeyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue { 

    } 
} 

Übrigens gibt Funktion nicht korrekt RectValue. Was ist falsch daran?Tastaturproblem in iOS11

+0

Was im rect falsch ist, Sie bekommen? – Vakas

+0

Dies enthält keine Höhe für QuickTypeBar. – Wang90925

+0

Welche Art von Bar? Sprechen Sie über die AutoKorrektur-Leiste? – Vakas

Antwort

0

Versuchen Sie folgendes:

NotificationCenter.default.addObserver(self, selector: #selector(self.keyboardWillHide), name: NSNotification.Name.UIKeyboardWillHide, object: nil) 

NotificationCenter.default.addObserver(self, selector: #selector(self.keyboardWillShow), name: NSNotification.Name.UIKeyboardWillShow, object: nil) 

func keyboardWillHide(notification: NSNotification) { 
     if let rect = (notification.userInfo?[UIKeyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue { 

     } 
    } 
func keyboardWillShow(notification: NSNotification) { 
     if let rect = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue { 

     } 
    } 
+0

'UIKeyboardFrameEndUserInfoKey' sollte in 'keyboardWillHide' und' UIKeyboardFrameBeginUserInfoKey' in 'keyboardWillShow' stehen – Vakas

Verwandte Themen