//
//  MPPositive_PresentationController.swift
//  MusicPlayer
//
//  Created by Mr.Zhou on 2024/5/10.
//

import UIKit
///自定义模态弹出类型
enum MPPositive_PresentModal{
    ///播放器弹出列表
    case PlayerList
}
class MPPositive_PresentationController: UIPresentationController {
    //蒙板
    fileprivate lazy var maskView: UIView = {
        let corverView = UIView()
        return corverView
    }()
    // MARK: - 系统回调(重载)
    override func containerViewWillLayoutSubviews() {
        super.containerViewWillLayoutSubviews()
        //根据模态状态确定弹出控制器的布局
        switch MPPositive_ModalType {
        case .PlayerList:
            presentedView?.snp.makeConstraints({ (make) in
                make.left.right.bottom.equalToSuperview()
                make.height.equalTo(380*width)
            })
        }
        //添加蒙版
        setMask()
    }
    // 添加蒙版
    fileprivate func setMask() -> Void {
        // 添加蒙版
        containerView?.insertSubview(maskView, at: 0)
        //设置蒙版的属性
        maskView.backgroundColor = UIColor(white: 0.0, alpha: 0.8)
        maskView.frame = containerView!.bounds
        let tap = UITapGestureRecognizer(target: self, action: #selector(maskClick(_:)))
        maskView.addGestureRecognizer(tap)
    }
    //蒙板点击事件
    @objc fileprivate func maskClick(_ sender:UITapGestureRecognizer){
        presentedViewController.dismiss(animated: true, completion: nil)
    }
}
