|
|
@@ -0,0 +1,143 @@
|
|
|
+//
|
|
|
+// LNPopupViewProtocol.swift
|
|
|
+// Lanu
|
|
|
+//
|
|
|
+// Created by OneeChan on 2025/11/14.
|
|
|
+//
|
|
|
+
|
|
|
+import Foundation
|
|
|
+import UIKit
|
|
|
+import SnapKit
|
|
|
+
|
|
|
+enum LNPopupViewHeight {
|
|
|
+ case auto
|
|
|
+ case percent(CGFloat)
|
|
|
+ case height(CGFloat)
|
|
|
+}
|
|
|
+
|
|
|
+protocol LNPopupViewProtocol: UIView {
|
|
|
+ var container: UIView { get }
|
|
|
+ var containerHeight: LNPopupViewHeight { get }
|
|
|
+}
|
|
|
+
|
|
|
+extension LNPopupViewProtocol {
|
|
|
+ func showHIn(_ targetView: UIView) {
|
|
|
+ if superview != nil, superview != targetView {
|
|
|
+ removeFromSuperview()
|
|
|
+ }
|
|
|
+ targetView.addSubview(self)
|
|
|
+ self.snp.makeConstraints { make in
|
|
|
+ make.edges.equalToSuperview()
|
|
|
+ }
|
|
|
+ if container.superview == nil {
|
|
|
+ self.addSubview(container)
|
|
|
+ }
|
|
|
+ container.snp.remakeConstraints { make in
|
|
|
+ make.leading.equalTo(self.snp.trailing)
|
|
|
+ make.width.equalToSuperview()
|
|
|
+ make.bottom.equalToSuperview()
|
|
|
+ switch containerHeight {
|
|
|
+ case .percent(let percent):
|
|
|
+ make.height.equalToSuperview().multipliedBy(percent)
|
|
|
+ case .height(let height):
|
|
|
+ make.height.equalTo(height)
|
|
|
+ case .auto: break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ layoutIfNeeded()
|
|
|
+
|
|
|
+ container.snp.remakeConstraints { make in
|
|
|
+ make.leading.equalToSuperview()
|
|
|
+ make.width.equalToSuperview()
|
|
|
+ make.bottom.equalToSuperview()
|
|
|
+ switch containerHeight {
|
|
|
+ case .percent(let percent):
|
|
|
+ make.height.equalToSuperview().multipliedBy(percent)
|
|
|
+ case .height(let height):
|
|
|
+ make.height.equalTo(height)
|
|
|
+ case .auto: break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ UIView.animate(withDuration: 0.2) {
|
|
|
+ self.layoutIfNeeded()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ func dismissH() {
|
|
|
+ container.snp.remakeConstraints { make in
|
|
|
+ make.leading.equalTo(self.snp.trailing)
|
|
|
+ make.width.equalToSuperview()
|
|
|
+ make.bottom.equalToSuperview()
|
|
|
+ switch containerHeight {
|
|
|
+ case .percent(let percent):
|
|
|
+ make.height.equalToSuperview().multipliedBy(percent)
|
|
|
+ case .height(let height):
|
|
|
+ make.height.equalTo(height)
|
|
|
+ case .auto: break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ UIView.animate(withDuration: 0.2) {
|
|
|
+ self.layoutIfNeeded()
|
|
|
+ } completion: { _ in
|
|
|
+ self.removeFromSuperview()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ func showVIn(_ targetView: UIView) {
|
|
|
+ if superview != nil, superview != targetView {
|
|
|
+ removeFromSuperview()
|
|
|
+ }
|
|
|
+ targetView.addSubview(self)
|
|
|
+ self.snp.makeConstraints { make in
|
|
|
+ make.edges.equalToSuperview()
|
|
|
+ }
|
|
|
+ if container.superview == nil {
|
|
|
+ self.addSubview(container)
|
|
|
+ }
|
|
|
+ container.snp.remakeConstraints { make in
|
|
|
+ make.leading.trailing.equalToSuperview()
|
|
|
+ make.top.equalTo(self.snp.bottom)
|
|
|
+ switch containerHeight {
|
|
|
+ case .percent(let percent):
|
|
|
+ make.height.equalToSuperview().multipliedBy(percent)
|
|
|
+ case .height(let height):
|
|
|
+ make.height.equalTo(height)
|
|
|
+ case .auto: break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ layoutIfNeeded()
|
|
|
+
|
|
|
+ container.snp.remakeConstraints { make in
|
|
|
+ make.leading.trailing.bottom.equalToSuperview()
|
|
|
+ switch containerHeight {
|
|
|
+ case .percent(let percent):
|
|
|
+ make.height.equalToSuperview().multipliedBy(percent)
|
|
|
+ case .height(let height):
|
|
|
+ make.height.equalTo(height)
|
|
|
+ case .auto: break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ UIView.animate(withDuration: 0.2) {
|
|
|
+ self.layoutIfNeeded()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ func dismissV() {
|
|
|
+ container.snp.remakeConstraints { make in
|
|
|
+ make.leading.trailing.equalToSuperview()
|
|
|
+ make.top.equalTo(self.snp.bottom)
|
|
|
+ switch containerHeight {
|
|
|
+ case .percent(let percent):
|
|
|
+ make.height.equalToSuperview().multipliedBy(percent)
|
|
|
+ case .height(let height):
|
|
|
+ make.height.equalTo(height)
|
|
|
+ case .auto: break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ UIView.animate(withDuration: 0.2) {
|
|
|
+ self.layoutIfNeeded()
|
|
|
+ } completion: { _ in
|
|
|
+ self.removeFromSuperview()
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|