【问题标题】:iOS: View heights not adding upiOS:视图高度未累加
【发布时间】:2013-07-12 15:58:07
【问题描述】:

我正在尝试在我的应用程序中使用 UIWebView 实现自定义浏览器。 XIB 文件在高度 35px 的顶部有一个地址栏,在高度 35px 的底部有一个导航栏。所以,我在 viewDidLoad() 中动态添加 webView。这就是我设置webview框架的方式,

webView.frame=CGRectMake(0, top.frame.size.height, self.view.frame.size.width, self.view.bounds.size.height-(top.frame.size.height+bottom.frame.size.height));

我认为这可以解决问题,并且 webview 将准确地固定在地址和导航栏之间。但是,在设备或模拟器上运行时,webview 很容易覆盖导航栏。这些是控制器中各个视图的高度。

self.view.bounds.size.height = 548.000000,top.view.bounds.size.height = 35,bottom.view.bounds.size.height = 35。

我不确定是什么问题。有人可以告诉我吗?

【问题讨论】:

  • 你试过把这行放在viewDidLayoutSubviews吗?
  • 谢谢,完成了这项工作。你能告诉我为什么 viewDidLoad() 和 viewDidLayoutSubviews() 中的 self.view.bounds.size.height 值不同吗?在第一种情况下,高度为 548,在另一种情况下,高度为 460。
  • viewDidLoad 中的视图布局不完整,因此直到视图控制器生命周期的后期尺寸才准确/可靠。

标签: ios uiwebview


【解决方案1】:

不要对帧大小进行硬编码。从 superview 的视图中获取目标尺寸:

`webView.frame = self.view.bounds;`

并确保您的 Web 视图的 autoresizingMask 设置为:

`UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight`.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-09-14
    • 2015-01-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-05
    • 2017-11-08
    • 1970-01-01
    相关资源
    最近更新 更多