为什么我的视图没有相应增长到它内部的textView(swift)?

时间:2016-10-02 23:32:48

标签: ios swift uitextview uistoryboard nslayoutconstraint

我有一个view个应用,我有- top space 0 to MapView - trailing and leading 0 - bottom: 49 to superview (it's embedded in tab controller so with value 49 it's exactly above the tab controls) 嵌入式textView

看起来像这样:

enter image description here

我的- leading, bottom, top 4 to view border - trailing 8 to button - height 30 位于地图下方,因此它有约束条件:

textView

textView有标准约束:

func keyboardWillChangeFrame(notification: NSNotification) {
    let endFrame = (notification.userInfo![UIKeyboardFrameEndUserInfoKey] as! NSValue).CGRectValue()

    if(isKeyboardShown == true)
    {
        bottomConstraint.constant = CGRectGetHeight(view.bounds) - endFrame.origin.y+49
        self.view.layoutIfNeeded()

        isKeyboardShown = false
    } else {
        //scrollToBottom()
        bottomConstraint.constant = CGRectGetHeight(view.bounds) - endFrame.origin.y
        self.view.layoutIfNeeded()
        isKeyboardShown = true
    }

}

当我运行应用程序时,一切都很好,我看到地图,我看到它下面的bottomConstraint。当我开始在IBOutlet中输入内容时,键盘就会出现问题(感谢:

=0

,其中textViewfunc textViewDidChange(textView: UITextView) { let fixedWidth = textView.frame.size.width textView.sizeThatFits(CGSize(width: fixedWidth, height: CGFloat.max)) let newSize = textView.sizeThatFits(CGSize(width: fixedWidth, height: CGFloat.max)) var newFrame = textView.frame newFrame.size = CGSize(width: max(newSize.width, fixedWidth), height: newSize.height) textView.frame = newFrame } 的底部约束(textView)的textView。无论如何,我添加了这个方法:

textView

我希望textView改变它的大小。它正在发生,但view扩展到底部 - 我的意思是当用户开始编写多行时,view部分位于键盘下,而不是覆盖越来越多的地图部分。更重要的是,在下降时,textView会超过灰色view - 因此HomeKit本身不会扩展。

如何解决这个问题,以便HomeKitprint(accessory.services.count) 成长为每一个新行覆盖越来越多的地图?我不希望它部分隐藏在键盘下面。

0 个答案:

没有答案