Advertisement
Guest User

Untitled

a guest
Dec 9th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. webViewContent.scrollView.bounces = false
  2. webViewContent.scrollView.bouncesZoom = false
  3. webViewContent.scrollView.delegate = self
  4. webViewContent.scalesPageToFit = true
  5.  
  6. var htmlString = "<html><head>... ... a really long string that creates a table"
  7. webViewContent.loadHTMLString(htmlString, baseURL: nil)
  8.  
  9. func scrollViewDidZoom(_ scrollView: UIScrollView) {
  10. if(scrollView != webViewTitle.scrollView){
  11. var zoomPadding:CGFloat = 0.0
  12. if((currentZoomScale*webViewContent.scrollView.zoomScale) < 1){
  13. zoomPadding = 0.5*(-acos(currentZoomScale*webViewContent.scrollView.zoomScale)*180.0/CGFloat.pi)
  14. }else{
  15. zoomPadding = 0.5*acos(2-(currentZoomScale*webViewContent.scrollView.zoomScale))*180.0/CGFloat.pi
  16. }
  17. webViewTitle.scrollView.zoom(to: CGRect(x: webViewContent.scrollView.contentOffset.x,
  18. y: (355*currentZoomScale*webViewContent.scrollView.zoomScale) + zoomPadding,
  19. width: webViewTitle.scrollView.bounds.width/currentZoomScale/webViewContent.scrollView.zoomScale,
  20. height: webViewTitle.scrollView.bounds.height/currentZoomScale/webViewContent.scrollView.zoomScale),
  21. animated: false)
  22. }
  23. }
  24. func scrollViewDidScroll(_ scrollView: UIScrollView) {
  25. var zoomPadding:CGFloat = 0.0
  26. if((currentZoomScale*webViewContent.scrollView.zoomScale) < 1){
  27. zoomPadding = 0.5*(-acos(currentZoomScale*webViewContent.scrollView.zoomScale)*180.0/CGFloat.pi)
  28. }else{
  29. zoomPadding = 0.5*acos(2-(currentZoomScale*webViewContent.scrollView.zoomScale))*180.0/CGFloat.pi
  30. }
  31. if(scrollView == webViewTitle.scrollView){
  32. webViewTitle.scrollView.contentOffset.y = (355*currentZoomScale*webViewContent.scrollView.zoomScale) + zoomPadding
  33. webViewContent.scrollView.contentOffset.x = webViewTitle.scrollView.contentOffset.x
  34. }else{
  35. webViewTitle.scrollView.contentOffset.y = (355*currentZoomScale*webViewContent.scrollView.zoomScale) + zoomPadding
  36. webViewTitle.scrollView.contentOffset.x = webViewContent.scrollView.contentOffset.x
  37. }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement