2

I'm trying to adjust the inputAccessoryView height base on the UITextView inside the inputAccessoryView view just like iOS Native Message App. I'm able to adjust the hight of UITextView but can't make the inputAccessoryView to change the hight according to UITextView line. How is this possible in Swift?

UITextView Hight Adjustment:

func textViewDidChange(textView: UITextView) {
    var frame: CGRect  = MessageField.frame
    frame.size = MessageField.contentSize
    MessageField.frame = frame
}

I have read some QA in stack overflow but non of them seems to be working for me, I have tried the autoresizingMask [Flexible Hight], QA1, QA2.

Current Situation: The UITextView resize hight, but not the input accessory.

Screenshot: enter image description here

Community
  • 1
  • 1
Brian Nezhad
  • 6,148
  • 9
  • 44
  • 69
  • Doesn't the `inputAccessoryView` get attached to the top of the pop-up keyboard, not the text field? Do you perhaps mean a `leftInputView` or `rightInputView` to show something *inside* the field? – NRitH Aug 24 '15 at 19:12
  • Please see the screenshot, I have update the Question. @NRitH – Brian Nezhad Aug 24 '15 at 19:15
  • Do you mean the Send button, then? If so, and you're using constraints, then set a constraint between the text field and the Send button so that the `CenterY` constraint value is `0`. – NRitH Aug 24 '15 at 19:18
  • No i mean the inputaccessoryview, you see how is behind the keyboard and not expending? – Brian Nezhad Aug 24 '15 at 19:19
  • I need to figure out a way to change the constrain hight of the inputaccessoryview `constant` everytime a line is added in UITextView – Brian Nezhad Aug 24 '15 at 19:21
  • OH, I see it now. I don't think that you need to adjust the *height* of the accessory view when the number of lines change, but instead you want to change the `UIScrollView`'s `contentOffset` to move the content up. The height of the accessory view is a separate problem. Give it an explicit size, and take its height into consideration when you adjust the `contentOffset` when the keyboard appears and disappears. – NRitH Aug 24 '15 at 19:24
  • @NRitH can you show me that in code please? – Brian Nezhad Aug 24 '15 at 19:26

0 Answers0