ios - UIWebView - get content height -


i need update height of uiview based on height of inner web view. problem is, web view height calculated based on anchors parent , incorrect.

i have created custom uiview:

class scrollablecontentview : uiview {     var panelwebview: additionaldatawebview = {         let web = additionaldatawebview()         web.translatesautoresizingmaskintoconstraints = false         return web     }()      var header: uilabel = {         let fs = uilabel()         fs.translatesautoresizingmaskintoconstraints = false         return fs     }()      required init?(coder adecoder: nscoder) {         super.init(coder: adecoder)         initialize()     }      override init(frame: cgrect) {         super.init(frame: frame)         initialize()     }      private func initialize(){         panelwebview.parent = self          self.addsubview(header)         self.addsubview(panelwebview)          setupconstraints()     }      private func setupconstraints(){          nslayoutconstraint.activate([             header.topanchor.constraint(equalto: self.topanchor, constant: 2),             header.trailinganchor.constraint(equalto: self.trailinganchor),             header.leadinganchor.constraint(equalto: self.leadinganchor),             header.heightanchor.constraint(equaltoconstant: 80),              panelwebview.topanchor.constraint(equalto: header.bottomanchor),             panelwebview.leadinganchor.constraint(equalto: self.leadinganchor),             panelwebview.trailinganchor.constraint(equalto: self.trailinganchor),             panelwebview.bottomanchor.constraint(equalto:  self.bottomanchor),              //total height - header height + web view height             self.heightanchor.constraint(equaltoconstant:80)         ])      } } 

and have extended uiwebview

class additionaldatawebview : uiwebview, uiwebviewdelegate {      public weak var parent: scrollablecontentview? = nil      override init(frame: cgrect) {         super.init(frame: frame)         self.delegate = self         self.scrollview.isscrollenabled = false         self.scrollview.bounces = false      }      required init?(coder adecoder: nscoder) {         super.init(coder: adecoder)         self.delegate = self         self.scrollview.isscrollenabled = false         self.scrollview.bounces = false     }      func load() {         self.loadrequest(urlrequest(url: url(string: "someurl")!))     }      func webviewdidfinishload(_ webview: uiwebview) {         let webheight = self.scrollview.contentsize.height                    print("content height: ", webheight)          parent?.heightanchor.constraint(equaltoconstant: 80 + webheight)     }  } 

problem height obtained in webviewdidfinishload based on parent height , not on content actual height. how solve this?


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -