UITabBarController中的UINavigationController在视图底部和键盘之间有一个间隙

时间:2015-04-25 07:16:43

标签: ios uinavigationcontroller keyboard autolayout uitabbarcontroller

我有一个UITabBarController,其标签为UINavigationControllers

当键盘打开时,视图底部与键盘之间存在奇怪的间隙。我检查了所有约束,看起来很好。

我有一个不同的ViewController,其UITextView并没有显示它之间的差距。

这是我的代码,它将键盘高度添加到最底部的约束,以便它正确滚动并且不会隐藏任何内容:

func setupKeyboardObserver() {
    NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("keyboardWasShown:"), name:UIKeyboardWillShowNotification, object: nil)
    NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("keyboardWillHide:"), name:UIKeyboardWillHideNotification, object: nil)
}

func keyboardWasShown(notification: NSNotification) {
    let info = notification.userInfo!
    let keyboardFrame: CGRect = (info[UIKeyboardFrameEndUserInfoKey] as! NSValue).CGRectValue()

    UIView.animateWithDuration(0.1, animations: { () -> Void in
        self.bottomConstraint.constant = keyboardFrame.size.height
    })
}

func keyboardWillHide(notification: NSNotification) {
    var info = notification.userInfo!
    var keyboardFrame: CGRect = (info[UIKeyboardFrameEndUserInfoKey] as! NSValue).CGRectValue()

    UIView.animateWithDuration(0.1, animations: { () -> Void in
        self.bottomConstraint.constant = 0
    })
}

enter image description here

enter image description here

0 个答案:

没有答案