NCMainChangeHeightWebView.swift 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. //
  2. // NCMainChangeHeightWebView.swift
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 09/01/2020.
  6. // Copyright © 2020 TWS. All rights reserved.
  7. //
  8. import Foundation
  9. class NCMainChangeHeightWebView: UIView {
  10. let appDelegate = UIApplication.shared.delegate as! AppDelegate
  11. var startPosition: CGPoint?
  12. var originalHeight: CGFloat = 0
  13. let minHeight: CGFloat = 10
  14. let maxHeight: CGFloat = UIScreen.main.bounds.size.height/3
  15. @IBOutlet weak var imageDrag: UIImageView!
  16. required init?(coder: NSCoder) {
  17. super.init(coder: coder)
  18. NotificationCenter.default.addObserver(self, selector: #selector(self.changeTheming), name: NSNotification.Name(rawValue: "changeTheming"), object: nil)
  19. }
  20. @objc func changeTheming() {
  21. imageDrag.image = CCGraphics.changeThemingColorImage(UIImage(named: "dragHorizontal"), width: 20, height: 10, color: NCBrandColor.sharedInstance.brandText)
  22. }
  23. override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
  24. let touch = touches.first
  25. startPosition = touch?.location(in: self)
  26. originalHeight = self.frame.height
  27. }
  28. override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
  29. let touch = touches.first
  30. let endPosition = touch?.location(in: self)
  31. let difference = endPosition!.y - startPosition!.y
  32. let differenceSectionWebViewHeight = appDelegate.activeMain.viewSectionWebViewHeight.constant + difference
  33. if differenceSectionWebViewHeight <= minHeight {
  34. appDelegate.activeMain.viewSectionWebViewHeight.constant = minHeight
  35. }
  36. else if differenceSectionWebViewHeight >= maxHeight {
  37. appDelegate.activeMain.viewSectionWebViewHeight.constant = maxHeight
  38. }
  39. else {
  40. appDelegate.activeMain.viewSectionWebViewHeight.constant = differenceSectionWebViewHeight
  41. }
  42. // save position
  43. let currentviewSectionWebViewHeight = Int(appDelegate.activeMain.viewSectionWebViewHeight.constant)
  44. CCUtility.setViewSectionWebViewHeight(currentviewSectionWebViewHeight)
  45. }
  46. }