Ich habe einen View-Controller mit Scroll innen und ich stellte es auf diese Weise (mit automatischen Layout) in Storyboard:Scroll Ansicht und Tastatur Ausgabe Swift
Wie Sie sehen, ich alle Objekte in der hinzufügen letzte Ansicht ('viewsotto') im Scrollview. Mein Problem ist, dass: Einige dieser Objekte sind Textfeld und ich möchte, dass, wenn ich darauf tippen und Tastatur zeigt, es kann das Textfeld sein, so dass ich sehen kann, was ich darin schreibe. Aus diesem Grund habe ich es auf diese Weise tun:
NotificationCenter.default.addObserver(self, selector: #selector(userProfiloGiusto.keyboardWillShow), name: NSNotification.Name.UIKeyboardWillShow, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(userProfiloGiusto.keyboardWillHide), name: NSNotification.Name.UIKeyboardWillHide, object: nil)
func keyboardWillShow(notification: NSNotification) {
if let keyboardSize = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue {
if self.view.frame.origin.y == 0{
self.view.frame.origin.y -= keyboardSize.height
}
}
}
func keyboardWillHide(notification: NSNotification) {
if let keyboardSize = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue {
if self.view.frame.origin.y != 0{
self.view.frame.origin.y += keyboardSize.height
}
}
}
aber es funktioniert nicht. Was mache ich falsch?
überprüfen Sie keine Notwendigkeit, https://github.com/hackiftekhar/IQKeyboardManager zu codieren – karthikeyan
@karthikeyan hat Recht. es ist auch einfach zu implementieren. – vaibby
danke. es ist wunderbar!! –