//
|
// ChooseOptView.swift
|
// XQMuse
|
//
|
// Created by 无故事王国 on 2024/8/15.
|
//
|
|
import UIKit
|
import JQTools
|
|
class ChooseOptView: UIView,JQNibView{
|
|
@IBOutlet weak var view_container: UIView!
|
@IBOutlet weak var tableView: UITableView!
|
@IBOutlet weak var cons_hight: NSLayoutConstraint!
|
@IBOutlet weak var cons_bottom: NSLayoutConstraint!
|
@IBOutlet weak var cons_cancel_bottom: NSLayoutConstraint!
|
private var items = [String]()
|
private var clouse:((Int)->Void)!
|
|
override func awakeFromNib() {
|
super.awakeFromNib()
|
|
tableView.delegate = self
|
tableView.dataSource = self
|
tableView.separatorStyle = .none
|
tableView.register(UITableViewCell.self, forCellReuseIdentifier: "_cell")
|
alpha = 0
|
cons_hight.constant = 0
|
cons_cancel_bottom.constant = UIDevice.jq_safeEdges.bottom
|
cons_bottom.constant = -JQ_ScreenW
|
layoutIfNeeded()
|
}
|
|
static func show(titles:[String],clouse:@escaping (Int)->Void){
|
let optView = ChooseOptView.jq_loadNibView()
|
optView.items = titles
|
optView.clouse = clouse
|
optView.frame = sceneDelegate?.window?.frame ?? .zero
|
sceneDelegate?.window?.addSubview(optView)
|
|
optView.cons_hight.constant = Double(titles.count) * 56
|
optView.cons_bottom.constant = -UIDevice.jq_safeEdges.bottom
|
UIView.animate(withDuration: 0.4) {
|
optView.alpha = 1
|
optView.layoutIfNeeded()
|
}
|
}
|
|
override func layoutSubviews() {
|
super.layoutSubviews()
|
view_container.jq_cornerPart(byRoundingCorners: [.topLeft,.topRight], radii: 22)
|
}
|
|
@IBAction func cancelAction(_ sender: Any) {
|
self.cons_bottom.constant = -JQ_ScreenW
|
UIView.animate(withDuration: 0.4) {
|
self.alpha = 0
|
self.layoutIfNeeded()
|
} completion: { _ in
|
self.removeFromSuperview()
|
}
|
}
|
}
|
|
extension ChooseOptView:UITableViewDelegate & UITableViewDataSource{
|
|
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
clouse(indexPath.row)
|
self.cons_bottom.constant = -JQ_ScreenW
|
UIView.animate(withDuration: 0.4) {
|
self.alpha = 0
|
self.layoutIfNeeded()
|
} completion: { _ in
|
self.removeFromSuperview()
|
}
|
}
|
|
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
return items.count
|
}
|
|
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
let cell = tableView.dequeueReusableCell(withIdentifier: "_cell")
|
cell!.textLabel?.font = UIFont.systemFont(ofSize: 15, weight: .medium)
|
cell!.textLabel?.textColor = UIColor(hexString: "#92A87D")
|
cell!.selectionStyle = .none
|
cell?.textLabel?.textAlignment = .center
|
cell?.textLabel?.text = items[indexPath.row]
|
return cell!
|
}
|
|
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
|
return 56
|
}
|
}
|