|
| 1 | +// |
| 2 | +// PopupController.swift |
| 3 | +// HTComponents |
| 4 | +// |
| 5 | +// Created by mac on 2021/6/10. |
| 6 | +// |
| 7 | + |
| 8 | +import UIKit |
| 9 | +import SnapKit |
| 10 | + |
| 11 | +@objc(HTPopupViewProtocol) |
| 12 | +public protocol PopupViewProtocol: NSObjectProtocol { |
| 13 | + weak var popupControllerDelegate: PopupControllerProtocol? { set get } |
| 14 | +} |
| 15 | + |
| 16 | +@objc(HTPopupControllerProtocol) |
| 17 | +public protocol PopupControllerProtocol: NSObjectProtocol { |
| 18 | + func dismiss() |
| 19 | +} |
| 20 | + |
| 21 | +@objc(HTPopupController) |
| 22 | +@objcMembers |
| 23 | +open class PopupController: UIViewController, PopupControllerProtocol { |
| 24 | + |
| 25 | + public let customView: UIView & PopupViewProtocol |
| 26 | + |
| 27 | + public init(_ customView: UIView & PopupViewProtocol) { |
| 28 | + self.customView = customView |
| 29 | + super.init(nibName: nil, bundle: nil) |
| 30 | + self.customView.popupControllerDelegate = self |
| 31 | + modalPresentationStyle = .overFullScreen |
| 32 | + modalTransitionStyle = .crossDissolve |
| 33 | + } |
| 34 | + |
| 35 | + required public init?(coder: NSCoder) { |
| 36 | + fatalError("init(coder:) has not been implemented") |
| 37 | + } |
| 38 | + |
| 39 | + open override func viewDidLoad() { |
| 40 | + super.viewDidLoad() |
| 41 | + |
| 42 | + view.backgroundColor = UIColor.black.withAlphaComponent(0.3) |
| 43 | + |
| 44 | + view.addSubview(self.customView) |
| 45 | + self.customView.snp.makeConstraints { make in |
| 46 | + make.center.equalToSuperview() |
| 47 | + make.width.height.lessThanOrEqualToSuperview() |
| 48 | + } |
| 49 | + |
| 50 | + } |
| 51 | + |
| 52 | + public func dismiss() { |
| 53 | + dismiss(animated: true, completion: nil) |
| 54 | + } |
| 55 | + |
| 56 | +} |
0 commit comments