从 UIViewController 的 viewWillAppear 事件设置 UITextView 的高度

发布于 2024-10-09 09:23:25 字数 635 浏览 0 评论 0原文

我试图从 UIViewController 的 viewWillAppear 事件设置 UITextView 的高度,代码如下:

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];

    textView.text = blah blah...
    textView.frame = CGRectMake(textView.frame.origin.x, textView.frame.origin.y,
      textView.frame.size.width, textView.frame.size.height-20);
}

但是,它似乎忽略了我的大小调整,就好像在调用此事件后,文本视图被其他东西调整大小。

我做错了什么?有什么好的方法可以做到这一点吗?

谢谢

-编辑-

通过将代码放入我的 viewDidAppear 而不是 viewWillAppear 中使其正常工作。 所以现在可以了。

虽然我很困惑为什么我需要这样做(从底部删除 20 像素) - 我的意思是它不应该调整大小以自动填充吗?为什么它调整到 20px 太长了?底部有一个标签栏,顶部有一个导航栏。这很令人困惑吗?

I'm trying to set the height of a UITextView from a UIViewController's viewWillAppear event, here's the code:

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];

    textView.text = blah blah...
    textView.frame = CGRectMake(textView.frame.origin.x, textView.frame.origin.y,
      textView.frame.size.width, textView.frame.size.height-20);
}

However, it seems to ignore my sizing, it's as though after this event is called, the textview is resized by something else.

What am i doing wrong? Is there some good way to do this?

Thanks

-edit-

Got it working by putting the code in my viewDidAppear instead of the viewWillAppear.
So it works now.

Although i'm puzzled why i need to do this (remove 20 pixels from the bottom) - i mean shouldn't it resize to fill automatically? Why is it resizing to 20px too long? There's a tab bar at the bottom and a nav bar up the top. Is that confusing it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

鼻尖触碰 2024-10-16 09:23:25

简单但明显的问题,文本是否改变,换句话说,插座是否连接在IB中?

JUSTA 提示:看看如何使用 CGRect 的辅助函数,例如:

textView.frame = CGRectInset(textView.frame, 0, 20);

Simple but obvious question, does the text change, in other words, is the outlet hooked up in IB?

JUSTA TIP: Look at using the helper functions for CGRect such as:

textView.frame = CGRectInset(textView.frame, 0, 20);
花辞树 2024-10-16 09:23:25

在仅包含此代码和单个 TextView 的应用程序中,调整大小会按预期进行。所以..这肯定是你的应用程序中的其他东西。

您是否可能在 viewDidAppear 中引用 contentsize 属性或其他内容?

In an app with just this code and a single TextView the resizing occurs as expected. So..it's definitely something else in your app.

Are you maybe referencing the contentsize property or something else in your viewDidAppear?

昔日梦未散 2024-10-16 09:23:25

通过将代码放入我的 viewDidAppear 而不是 viewWillAppear 中使其正常工作。
所以现在可以了。

虽然我很困惑为什么我需要这样做(从底部删除 20 像素) - 我的意思是它不应该调整大小以自动填充吗?为什么它调整到 20px 太长了?底部有一个标签栏,顶部有一个导航栏。

Got it working by putting the code in my viewDidAppear instead of the viewWillAppear.
So it works now.

Although i'm puzzled why i need to do this (remove 20 pixels from the bottom) - i mean shouldn't it resize to fill automatically? Why is it resizing to 20px too long? There's a tab bar at the bottom and a nav bar up the top.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文