当键盘以编程方式打开时,Swift Autolayouts不断变化

时间:2016-01-20 15:41:04

标签: swift autolayout

我正在使用Autolayout,在此页面上查看tableview并使用textfield查看。当键盘被打开时,子视图和tableview常量应该改变。问题在于我的代码只有子视图向上滑动但是tableview没有。

func keyboardWillShow(notification: NSNotification?) {

        guard let keyboardFrame = (notification?.userInfo?[UIKeyboardFrameEndUserInfoKey] as? NSValue)?.CGRectValue(),
            duration:NSTimeInterval = notification?.userInfo?[UIKeyboardAnimationDurationUserInfoKey] as? Double else {
            return
        }

        bottomConstraint.constant = keyboardFrame.size.height + 10
         BotTbl.constant = keyboardFrame.size.height + 10

        UIView.animateWithDuration(
            duration,
            animations: {
                self.view.layoutIfNeeded()
            },completion:nil)
    }

    func keyboardWillHide(notification: NSNotification?) {
        guard let duration = (notification?.userInfo?[UIKeyboardAnimationDurationUserInfoKey] as? Double) else {
            return
        }

        bottomConstraint.constant = 0
        BotTbl.constant = 10

        UIView.animateWithDuration(
            duration,
            animations:{
                self.view.layoutIfNeeded()
            },
            completion:nil)
    }

enter image description here

0 个答案:

没有答案