How to move content of UIViewController upwards as Keypad appears using Swift

后端 未结 2 912
谎友^
谎友^ 2021-01-07 09:05

I want to move the content of the bottom of my UIViewController upwards as the keypad appears. At the bottom of the view controller I have a UITextField and when the user cl

2条回答
  •  长发绾君心
    2021-01-07 09:25

    I'm not sure how the top rated answer works; isn't it supposed to be:

    func keyboardWillShow(notification: NSNotification) {
        if let info: NSDictionary = notification.userInfo {
            let value: NSValue = info.valueForKey(UIKeyboardFrameEndUserInfoKey) as NSValue
            let rect: CGRect = value.CGRectValue()
            view_comment.y = rect.height - view_comment.h
        }
    }
    

    Since you need to cast Dictionary to NSDictionary in order to access valueForkey?

提交回复
热议问题