开发者

Resizing UITextView for Landscape Orientation

开发者 https://www.devze.com 2023-02-13 12:11 出处:网络
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:

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

精彩评论

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