UITextView的框架未在viewWillAppear中设置 [英] UITextView's frame not set in viewWillAppear

查看:94
本文介绍了UITextView的框架未在viewWillAppear中设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用iOS 6和Xcode 4.6以及Interface Builder我在滚动条视图中添加 UITextView

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 受约束到 UITextView

在此代码中,框架位于的位置(0,0 )并且大小为(0,0)。因此,它不会调整我的 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;

它工作的唯一功能(大小大于0的帧)是:

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).

你能告诉我为什么我的 UITextView的框架是不正确以及如何解决这个问题?

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

有关您的信息,此视图会通过 TableViewCell (在故事板中配置)。

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

感谢您的帮助!

推荐答案

我得到了答案,感谢Cezar的评论。

I found the answer thanks to Cezar's comment.

答案可以在这里找到在Storyboard中获取子视图的帧

我实际上打过电话:

[_view layoutSubviews];

在我父母的观点中:

- (void) viewDidLayoutSubviews;

方法在访问框架之前有效。

method before accessing the frame and it works.

这篇关于UITextView的框架未在viewWillAppear中设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆