WKWebView added as Subview is not resized on rotation in Swift

前端 未结 4 967
眼角桃花
眼角桃花 2021-02-04 05:41

I\'m working on adding a new reading view to my browser app. It is another view controller, that only includes a WKWebView added as a subview with a button (and gesture) to clos

相关标签:
4条回答
  • 2021-02-04 06:01

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

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

    :)

    0 讨论(0)
  • 2021-02-04 06:03

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

    [self.webView setAutoresizingMask:UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth];
    
    0 讨论(0)
  • 2021-02-04 06:06

    swift 3 version:

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

    0 讨论(0)
  • 2021-02-04 06:17

    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.

    0 讨论(0)
提交回复
热议问题