UIWebView的sizeToFit只能工作一次
在我的自定义 UIViewController 中,我有两个不同的 UIWebView,我的自定义 UIViewController 是其委托。在 webViewDidFinishLoad:webView
中,我调用 [webView sizeToFit]
并且我可以确认它被调用两次,每个 UIWebView 调用一次。然而,令我非常沮丧的是,它似乎只影响第一个被调用的,而另一个则保持不变。显然它们的内容都超出了界限,所以我希望它们能够相应地调整大小。
现在,在这个问题上花费了大量时间之后,我该如何继续了解问题所在?
编辑:好吧,显然问题是当我调用 sizeToFit 时,我放置第二个 UIWebView 的视图在屏幕上不可见。在显示视图后延迟调用它会产生预期的行为。现在我必须找到一种方法来做到这一点而不显示它,因为我需要稍后可见。有想法吗?
In my custom UIViewController I have two distinct UIWebViews for which my custom UIViewController is the delegate. In webViewDidFinishLoad:webView
I call [webView sizeToFit]
and I can confirm it gets called twice, one for each UIWebView. However, to my great dismay, it only seems to affect the first one that gets called, while the other one remains unchanged. Obviously both their contents exceed the bounds, so I expect them to be resized accordingly.
Now, after lots of hours spent on this issue, how am I even supposed to proceed to understand what's wrong?
EDIT: Alright, apparently the problem is that the view in which I put the second UIWebView is not visible on the screen when I call sizeToFit. Calling it with a delay after the view is shown results in the expected behaviour. Now I have to find a way to do this without showing it, because I need to to be visible at a later time. Ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来在 viewDidAppear 上这样做就像一个魅力。
It seems that doing that on
viewDidAppear
works like a charm.