简体   繁体   English

iOS9 UIWebView窗口(框架)在iOS 8上的高度变化行为

[英]iOS9 UIWebView window (frame) height change behavior over iOS 8

I notice that the iOS 9 WebView does not behave the same as per iOS 8. 我注意到,iOS 9 WebView的行为与iOS 8不同。

That is, the content overflows the window despite a scrollview. 也就是说,尽管具有滚动视图,但内容仍会溢出窗口。

lazy var webView = UIWebView()

override func viewDidLoad() {
    super.viewDidLoad()

    view.addSubview(webView)
    webView.frame = view.frame
    webView.delegate = self

    // *** added over the original code in iOS 8, but does not solve anything.
    webView.layer.masksToBounds = true
    webView.scrollView.frame.size = view.frame.size
    webView.scrollView.contentSize = view.frame.size

    // Init with HTML5 app (existing working code in iOS 8)
    webView.scrollView.scrollEnabled = false
    view.backgroundColor =  UIColor.clearColor()
    webView.backgroundColor = self.view.backgroundColor
    let request = NSURLRequest(URL:basePath!)
    webView.loadRequest(request)

} }

Any idea that would help solve the issue? 有什么想法可以解决这个问题吗?

UPDATE : I added a screen shot (where I forced a height of 512) 更新:我添加了一个屏幕截图(在这里我强制高度为512) 在此处输入图片说明

Ok. 好。 I managed to find why the height was not handled the same way than in iOS8. 我设法找到了为什么高度与iOS8不同的方式。

Actually, iOS 8 "fixed" an issue on y side that iOS9 don't (which, on a way, is a better approach). 实际上,iOS 8在y方面“解决了” iOS9无法解决的问题(从某种意义上说,这是一种更好的方法)。

My index page was wrong in setting the following webkit meta: 我的索引页在设置以下Webkit元数据时出错:

<meta name="viewport" content="width=device-width, height=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=0">

As you can see, the height was wrongly written device-width. 如您所见,高度被错误地写入了设备宽度。 As I said, iOS8 was tolerant and "replaced" to the device-height, I guess. 正如我所说,iOS8可以容忍并且可以“替换”到设备高度。 iOS 9 doesn't. iOS 9没有。

I simply fixed to the meta as follows: 我只是将元数据固定如下:

<meta name="viewport" content="width=device-width, height=device-height, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=0">

device-height replaced device-width in the height parameter. device-height替换了height参数中的device-width。

Hope it helps. 希望能帮助到你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM