3

私はスタックオーバーフローでそれについてよく検索しますが、彼らの解決策によると、私のプログラムは言及と同じですが、まだ機能していません。

func subscribeToKeyboardNotifications() {
    NotificationCenter.default.addObserver(self, selector:Selector(("keyboardWillShow:")), name:NSNotification.Name.UIKeyboardWillShow, object: nil)
}


func keyboardWillShow(notification:NSNotification) {
    view.frame.origin.y -= getKeyboardHeight(notification: notification)
}
4

2 に答える 2

6

セレクターの引数は#selector(keyboardWillShow)、次のようにする必要があります。

func subscribeToKeyboardNotifications() {
    NotificationCenter.default.addObserver(self, selector:#selector(keyboardWillShow), name: .UIKeyboardWillShow, object: nil)
}

func keyboardWillShow(notification:NSNotification) {
    view.frame.origin.y -= getKeyboardHeight(notification: notification)
}
于 2016-10-14T02:16:06.653 に答える