WKWebView added as Subview is not resized on rotation in Swift

妖精的绣舞 提交于 2019-12-03 05:24:18

I managed to solve the problem by using this line of code:

self._webView!.autoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight

:)

Chetan Dobariya

swift 3 version:

webView?.autoresizingMask = [.flexibleWidth, .flexibleHeight]

I'm posting an answer for Objective-C, just in case if someone comes here looking for it

[self.webView setAutoresizingMask:UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth];

In fact, as WKWebView can only be added programmatically, it happens to have the autoresizing mask to constraints flag enabled by default (when adding components and constraints inside Interface Builder, it's usually disabled for you). I think the correct solution would be:

webView?.translatesAutoresizingMaskIntoConstraints = false

after adding the constraints/anchors.

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