UITextView does not resize in UIView

I have UIView

one that has three subheadings, two buttons, and one text view. One button is constrained to the left and bottom UIView

, and the other is constrained to the right and bottom. The text view is bounded at the top and bottom UIView

, as well as two buttons.

I am resizing UIView

when the text view resizes. I am executing logic in a textViewDidChange

function

func textViewDidChange(textView: UITextView) {
    var messageViewHeight = messageView.frame.height
    var messageY = messageView.frame.origin.y
    // Resize the message view if text view has multiple lines
    if (textView.contentSize.height > messageViewHeight) {
        messageViewHeight += origHeight
        messageY -= origHeight
    }
    // Set the message view frame
    messageView.frame = CGRect(x: 0, y: messageY, width: messageView.frame.size.width, height: messageViewHeight)
}

      

Where origHeight

is the original height UITextView

and messageView

is the parent UIView

.

UIView

gets the correct resize, but the problem is that the text view doesn't change. I don't have enough reputation to show images yet to show a screenshot.

It seems that all the sub-items are no longer limited at the bottom UIView

. Do I need to add constraints again? Or is there a better way to resize UIView

?

+3


source to share





All Articles