iOS webview leaves empty space before HTML content

假如想象 提交于 2020-02-28 18:47:06

问题


I have the simplest view. A webview with some static HTML code embedded using the loadHTMLStringmessage. The only thing I've modifed in the webview's properties from the storyboard is the "Scale page to fit" property (it's checked). However, as you can see in the image below, there's an empty space above the HTML that belongs to the webview (if I scroll the content it fills up that space). I've even tried just using...

<html>
<body><h1>Hello</h1></body>
</html>

... but the space is still there (so I don't think it has anything to do with the HTML code).

How can I remove that space?


回答1:


iOS adjusts the content inset only for the first view in the view hierarchy if it is UIScrollView or it's descendant (e.g. UITableView and UICollectionView, in your case its a UIWebView). If your view hierarchy includes multiple scroll views, automaticallyAdjustsScrollViewInsets will make adjustments only to the first one.

Here's how to change this behavior:

a) Interface Builder

Select the view controller Open Attributes inspector There's a property called "Adjust scroll view insets" in IB's attribute inspector (when a ViewController is selected) which is on by default.

b) Programmatically

Add this to i.e. viewDidLoad method

Obj-C: self.automaticallyAdjustsScrollViewInsets = NO;

Swift: self.automaticallyAdjustsScrollViewInsets = false




回答2:


Turn off adjusts scroll view insets.It's here:



来源:https://stackoverflow.com/questions/36465275/ios-webview-leaves-empty-space-before-html-content

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!