No Description

SideViewController.swift 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. //
  2. // SideViewController.swift
  3. // PaiAi
  4. //
  5. // Created by FFIB on 2018/12/12.
  6. // Copyright © 2018 FFIB. All rights reserved.
  7. //
  8. import UIKit
  9. open class SideViewController: UIViewController, PresentViewController {
  10. public var animator: PresentAnimatable = SideAnimator()
  11. open var animationView: UIView? {
  12. return nil
  13. }
  14. override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
  15. super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
  16. commonInit()
  17. }
  18. public required init?(coder aDecoder: NSCoder) {
  19. super.init(coder: aDecoder)
  20. commonInit()
  21. }
  22. override open func viewDidLoad() {
  23. super.viewDidLoad()
  24. view.isUserInteractionEnabled = true
  25. view.backgroundColor = UIColor(gray: 52, alpha: 0)
  26. configurationGestures()
  27. }
  28. private func commonInit() {
  29. modalPresentationStyle = .custom
  30. setTransitioningDelegate(self)
  31. }
  32. @objc public func disappear() {
  33. dismiss(animated: true, completion: nil)
  34. }
  35. }
  36. /// gesture
  37. fileprivate extension SideViewController {
  38. func configurationGestures() {
  39. configurationTapGesture()
  40. configurationSwipeGesture()
  41. }
  42. func configurationTapGesture() {
  43. let tap = UITapGestureRecognizer(target: self, action: #selector(disappear))
  44. tap.setDelegate(self)
  45. view.addGestureRecognizer(tap)
  46. }
  47. func configurationSwipeGesture() {
  48. let swipe = UISwipeGestureRecognizer(target: self, action: #selector(disappear))
  49. swipe.setDelegate(self)
  50. swipe.direction = .left
  51. view.addGestureRecognizer(swipe)
  52. }
  53. }