开发者

Resizing UITextView for Landscape Orientation

I have a basic View created in IB containing a UITableView and a UITextVIew. I size the UITextView programatically to fit its content as below:

CGRect frame = self.textView.frame;
frame.size.height = self.textView.contentSize.height;
self.textView.frame = frame;

This works fine for portrait orientation, but when in landscape the text view grow开发者_StackOverflow中文版s to accommodate the additional horizontal space (which is desired) but the above code makes the height larger than the content. From output statements, it appears as though the above code is not taking into account the new width of the text view.

Is there any way to take into account the new width in order to determine the correct height?


you must call setNeedsLayout after the rotation (from the controller's rotation callback) to tell the UITextView to recompute itself after the rotation.

Edit: OzzyTheGiant is correct setNeedsLayout , not layoutSubViews.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜