从 UIViewController 的 viewWillAppear 事件设置 UITextView 的高度
我试图从 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
简单但明显的问题,文本是否改变,换句话说,插座是否连接在IB中?
JUSTA 提示:看看如何使用 CGRect 的辅助函数,例如:
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 的应用程序中,调整大小会按预期进行。所以..这肯定是你的应用程序中的其他东西。
您是否可能在 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?
通过将代码放入我的 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.