SCScrollView.swift 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. //
  2. // SCScrollView.swift
  3. // SegmentedControl
  4. //
  5. // Created by Xin Hong on 15/12/30.
  6. // Copyright © 2015年 Teambition. All rights reserved.
  7. //
  8. import UIKit
  9. internal class SCScrollView: UIScrollView {
  10. override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
  11. if !isDragging {
  12. next?.touchesBegan(touches, with: event)
  13. } else {
  14. super.touchesBegan(touches, with: event)
  15. }
  16. }
  17. override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
  18. if !isDragging {
  19. next?.touchesMoved(touches, with: event)
  20. } else {
  21. super.touchesMoved(touches, with: event)
  22. }
  23. }
  24. override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
  25. if !isDragging {
  26. next?.touchesEnded(touches, with: event)
  27. } else {
  28. super.touchesEnded(touches, with: event)
  29. }
  30. }
  31. }
  32. internal extension SCScrollView {
  33. internal var parentViewController: UIViewController? {
  34. var parentResponder: UIResponder? = self
  35. while parentResponder != nil {
  36. parentResponder = parentResponder!.next
  37. if let viewController = parentResponder as? UIViewController {
  38. return viewController
  39. }
  40. }
  41. return nil
  42. }
  43. }