UIWebView
스크롤 뷰의 높이와 일치하도록 테이블 뷰 셀의 높이를 업데이트하려고합니다. UIWebView
은 테이블 뷰 셀의 하위 뷰입니다 . 상위 제어기에서확대/축소시 UITableViewCell의 제약 조건 업데이트가 UIWebView scrollView에서 제대로 작동하지 않습니다.
func scrollViewDidEndZooming(_ scrollView: UIScrollView, with view: UIView?, atScale scale: CGFloat) {
DispatchQueue.main.async {
print("\nscrollViewDidEndZooming")
print("webView.scrollView.contentSize.height: \(self.webView.scrollView.contentSize.height)")
print("webViewHeightConstraint: \(self.webViewHeightConstraint.constant)")
let height = self.webView.scrollView.contentSize.height
self.webViewHeightConstraint.constant = height
myDelegate.reloadTableView()
}
}
에
:
func reloadTableView() {
tableView.beginUpdates()
tableView.endUpdates()
}
웹보기에로드 된 HTML 내용이 있습니다. 문제는 didEndZooming
이 호출되고 높이 제약 조건이 업데이트 된 후 제대로 설정되지 않는 것입니다. 높이 제한은 크기가 커질 때까지 증가합니다. tableView 셀에서 높이 제한을 설정하는 것은 어떻게 든 피드백 루프를 만드는 것으로 보입니다.
어떻게하면 좋을까요? (그것은있는 ScrollView의 크기는 무제한의 성장없이 확대 된 값으로 크기를 조정해야합니다.)
업데이트 : 자체가 XIB 파일에 셀
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: WebViewCell.description(), for: indexPath) as! WebViewCell
//The cell delegate implements the didFinishLoad() function
cell.delegate = self
//TODO: I know this is not efficient, will update later.
if let html = viewModel.emailInfo?.htmlContent {
cell.loadHTMLString(html)
}
return cell
}
있다. 난 지금은 더미 뷰의 내부보기를 넣어 (이 문제가 해결되지 않았는지 확인하려고합니다.) 웹 뷰는 위쪽, 아래쪽, 왼쪽 및 오른쪽 가장자리에 제약 조건이 있습니다. 또한 웹 뷰의 높이 제약. 내가 셀의 높이를 결정하는 데 사용하기 위해 노력하고 있음을,이 높이 제한,
webViewHeightConstraint
입니다.
이 확대 및 축소의 몇 사이클 후 로그 출력됩니다.이다 새로운 높이 제한이 설정되기 전에 인쇄됩니다.
scrollViewDidEndZooming webView.scrollView.contentSize.height : 962.0,210 webViewHeightConstraint : 509.0
scrollViewDidEndZooming webView.scrollView.contentSize.height : 962.0 webViewHeightConstraint : 962.0
scrollViewDidEndZooming webView.scrollView.contentSize.height : 1531.0 webViewHeightConstraint : 962.0
scrollViewDidEndZooming webView.scrollView.contentSize .height : 1549.0 webViewHeightConstraint : 1531.0
scrollViewDidEndZooming webView.scrollView.contentSize.height : 2566.0,webViewHeightConstraint : 1549.0
scrollViewDidEndZooming webView.scrollView.contentSize.height : 2566.0 webViewHeightConstraint : 2566.0
scrollViewDidEndZooming webView.scrollView.contentSize.height : 4779.0 webViewHeightConstraint : 2566.0
scrollViewDidEndZooming webView.scrollView.contentSize .height : 4779.0 webViewHeightConstraint : 4779.0
scrollViewDidEndZooming webView.scrollView.contentSi ze.height : 10989.0 webViewHeightConstraint : 4779.0
scrollViewDidEndZooming webView.scrollView.contentSize.height : 10989.0 webViewHeightConstraint : 10989.0
scrollViewDidEndZooming webView.scrollView.contentSize.height : 25110.0 webViewHeightConstraint : 10989.0
scrollViewDidEndZooming webView.scrollView. contentSize.height : 25110.0 webViewHeightConstraint : 25110.0
'tableView (_ : cellForRowAt :)'메소드 안에 더 많은 코드를 제공해야한다.'tableViewCell'의 모양과'webViewHeightConstraint'는 무엇인가? 디버그 저장소가 있으면 쉽고 빠릅니다. – trungduc
예를 들어 Google에 도움이되는 몇 가지 정보를 게시해야합니다. 어떤 제약 조건들이 셀에 설정되어 있는지, 당신이 기대하는 것과 당신이 얻고있는 것을 보여주는 예입니다. '피드백 루프'를 확인하려면 scrollViewDidEndZooming에 로깅을 넣어 실제로 다중을 수행하는지 확인하십시오 타임스. 나는 또한 설정하려고하는 실제 높이를 확인하는 것이 좋습니다. 마지막으로 UIWebView는 현재 사용되지 않으므로 WKWebView를 살펴볼 것을 제안합니다. –
감사합니다. 몇 가지 이유로 UIWebView를 선택했습니다. 그러나 WKWebView를 다시 살펴 보겠습니다. – scord