我在堆栈溢出时搜索了很多关于它的信息,但根据他们的解决方案,我的程序与提及的相同,但仍无效。
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)
}
答案 0 :(得分: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)
}
答案 1 :(得分:1)
如果您没有使用#selector,那么它会给NSType带来未捕获的异常,因此会终止该应用。