2015-05-22 23 views
2

我有一個擴展的「消息工具欄」,其工作方式與Messages應用程序消息欄類似,用戶可以鍵入文本,整個欄應該爲每一行新文本增加高度(直到達到預定義的最大高度)。 我有它使用自動佈局設置和增長的消息欄工作得很好。但問題是,由於某種原因,每當我在消息欄的UITextView中出現一行新文本時,通過移動到遠離UITextView的框架,頂部行會略微截斷。使用Autolayout的UITextView動態高度 - 每條新線的文本截斷頂線

這裏是我當用戶鍵入到消息條碼:

func messageToolbarDidUpdateText(messageToolbar: MessageToolbar, textView: UITextView) 
{ 
    // Expand message bar to fit text view 
    let newTextViewHeight = max(self.messageToolbarMinHeight - messageToolbar.textViewTopPadding - messageToolbar.textViewBottomPadding, min(self.messageToolbarMaxHeight - messageToolbar.textViewTopPadding - messageToolbar.textViewBottomPadding, textView.contentSize.height)) // Check that message bar doesn't exceed the limits 
    textView.frame.size = CGSizeMake(textView.frame.width, newTextViewHeight) 

    let newMessageBarHeight = max(self.messageToolbarMinHeight, min(self.messageToolbarMaxHeight, textView.contentSize.height + messageToolbar.textViewTopPadding + messageToolbar.textViewBottomPadding)) // Check that message bar doesn't exceed the limits 
    self.messageToolbar.heightConstraint.constant = newMessageBarHeight 

    self.view.updateConstraintsIfNeeded() 
} 

這裏是我的意思截圖。注意第一行文本之前textview頂部第一個圖像中的空白。預計會在該消息欄達到最大高度並開始要求在文本視圖中滾動新行。但由於某些原因,即使消息欄仍不在最大高度,新行也會導致文本的頂行被截斷。它不只是一個滾動偏移或者作爲TextView的不允許滾動,直到消息欄滿足其最大高度: enter image description here enter image description here

回答

1

哦,對不起necroposting,但我有同樣的問題,終於找到了解決辦法。

所以basiclyüneeed:

將滾動文字正確的位置,如果ü沒有達到最大的工具欄的高度。如果你達到它,比你的文本視圖內容大小高於它的高度,你不應該有這個問題。

編輯:積分爲 https://stackoverflow.com/a/19047464/1316040提及HPGrowingTextView。 https://github.com/HansPinckaers/GrowingTextView ...好吧,現有的 https://github.com/KennethTsang/GrowingTextView爲實際的代碼行scrollRangeToVisible

+0

謝謝!花了兩個小時試圖解決這個問題 –

相關問題