| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- //
- // MOPopupViewProtocol.swift
- // MiMoLive
- //
- // Created by OneeChan on 2025/9/25.
- //
- import Foundation
- import UIKit
- enum PopupViewHeight {
- case percent(CGFloat)
- case height(CGFloat)
- }
- protocol MOPopupViewProtocol: UIView {
- var container: UIView { get }
- var containerHeight: PopupViewHeight { get }
- }
- extension MOPopupViewProtocol {
- 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()
- if case .percent(let percent) = containerHeight {
- make.height.equalToSuperview().multipliedBy(percent)
- } else if case .height(let height) = containerHeight {
- make.height.equalTo(height)
- }
- }
- layoutIfNeeded()
-
- container.snp.remakeConstraints { make in
- make.leading.equalToSuperview()
- make.width.equalToSuperview()
- make.bottom.equalToSuperview()
- if case .percent(let percent) = containerHeight {
- make.height.equalToSuperview().multipliedBy(percent)
- } else if case .height(let height) = containerHeight {
- make.height.equalTo(height)
- }
- }
- UIView.animate(withDuration: 0.2) {
- self.layoutIfNeeded()
- }
- NotificationCenter.default.post(name: NSNotification.Name("MOShowLivePagesVCCannotScroll"), object: nil)
- }
-
- func dismissH() {
- container.snp.remakeConstraints { make in
- make.leading.equalTo(self.snp.trailing)
- make.width.equalToSuperview()
- make.bottom.equalToSuperview()
- if case .percent(let percent) = containerHeight {
- make.height.equalToSuperview().multipliedBy(percent)
- } else if case .height(let height) = containerHeight {
- make.height.equalTo(height)
- }
- }
- UIView.animate(withDuration: 0.2) {
- self.layoutIfNeeded()
- } completion: { _ in
- self.removeFromSuperview()
- }
- NotificationCenter.default.post(name: NSNotification.Name("MOShowLivePagesVCCanScroll"), object: nil)
- }
-
- 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)
- if case .percent(let percent) = containerHeight {
- make.height.equalToSuperview().multipliedBy(percent)
- } else if case .height(let height) = containerHeight {
- make.height.equalTo(height)
- }
- }
- layoutIfNeeded()
-
- container.snp.remakeConstraints { make in
- make.leading.trailing.bottom.equalToSuperview()
- if case .percent(let percent) = containerHeight {
- make.height.equalToSuperview().multipliedBy(percent)
- } else if case .height(let height) = containerHeight {
- make.height.equalTo(height)
- }
- }
- UIView.animate(withDuration: 0.2) {
- self.layoutIfNeeded()
- }
- NotificationCenter.default.post(name: NSNotification.Name("MOShowLivePagesVCCannotScroll"), object: nil)
- }
-
- func dismissV() {
- container.snp.remakeConstraints { make in
- make.leading.trailing.equalToSuperview()
- make.top.equalTo(self.snp.bottom)
- if case .percent(let percent) = containerHeight {
- make.height.equalToSuperview().multipliedBy(percent)
- } else if case .height(let height) = containerHeight {
- make.height.equalTo(height)
- }
- }
- UIView.animate(withDuration: 0.2) {
- self.layoutIfNeeded()
- } completion: { _ in
- self.removeFromSuperview()
- }
- NotificationCenter.default.post(name: NSNotification.Name("MOShowLivePagesVCCanScroll"), object: nil)
- }
- }
|