'Stop Vertical scrolling of WebView in Tableview header
One of the cells in a UITableView contains a scroll view. I want to be able to scroll the content in the cell horizontally, but NOT vertically.
How can I achieve this?
Additionally, the scroll view is a subview of UIWebView, so I cannot control its content size.
I have tried setting the content offset directly, but this prevents the entire table from being scrolled. I want the table to scroll vertically, but not the content in the cell.
here is code of I stop vertical scrolling of webview in scrollview delegate-
initialisation of web-view here -
let bodyTextView: WKWebView = {
// preferences
let preferences = WKPreferences()
preferences.javaScriptEnabled = true
let configuration = WKWebViewConfiguration()
configuration.dataDetectorTypes = [.all]
// webview
let webView = WKWebView(frame: .zero, configuration: configuration)
webView.contentMode = .scaleToFill
webView.scrollView.showsVerticalScrollIndicator = false
webView.scrollView.tag = 2
webView.scrollView.delegate = self
return web
}()
func scrollViewDidScroll(_ scrollView: UIScrollView) {
//here is code to disable vertical scrolling for webview if scroll view tag is equal to 2 set while initialising the webview.
if scrollView.tag ==2 {
DispatchQueue.main.async {
scrollView.contentOffset = CGPoint(x: scrollView.contentOffset.x, y: 0)
}
}
//below code is used for Tableview-
let page = scrollView.contentOffset.x / view.frame.width
pageControl.currentPage = Int(page)
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
