UITextView's frame not set in viewWillAppear [duplicate]

耗尽温柔 提交于 2019-12-12 01:48:33

问题


I'm using iOS 6 and Xcode 4.6 and with the Interface Builder I'm adding a UITextView in a scrollbar view.

I disabled the scrolling for the Text View and I would like to dynamically resize the Text View so that we can view the full content.

I tried with the following code in my controller :

- (void)viewWillAppear:(BOOL)animated {
    CGRect frame = _description.frame;
    frame.size.height = _description.contentSize.height;
    _description.frame = frame;
}

_description is bound to the UITextView.

In this code the frame is at position (0, 0) and has a size of (0, 0). As a consequence it does not resize my UITextView.

I also tried to resize the view in these functions with no success :

- (void)viewDidLoad;
- (void)viewDidLayoutSubviews;

The only function where it works (the frame as a size greater than 0) is :

- (void)viewDidAppear:(BOOL)animated

However, at this point the view is already visible and we can see the Text View resizing (which is not what I want. I want it to resize before the user can see the view).

Can you tell me why my UITextView's frame is not correct and how I can solve this issue ?

For your information, this view is displayed automatically with the push method by a TableViewCell (configured in the storyboard).

Thank you for your help!


回答1:


I found the answer thanks to Cezar's comment.

The answer can be found here Gettting subViews' frames in Storyboard .

I actually called :

[_view layoutSubviews];

on my parent's view in the :

- (void) viewDidLayoutSubviews;

method before accessing the frame and it works.



来源:https://stackoverflow.com/questions/17907178/uitextviews-frame-not-set-in-viewwillappear

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!