//
|
// ChooseOptTitleView.swift
|
// XQMuse
|
//
|
// Created by 无故事王国 on 2024/9/10.
|
//
|
|
import UIKit
|
import JQTools
|
|
class ChooseOptTitleView: UIView,JQNibView{
|
@IBOutlet weak var label_title: UILabel!
|
@IBOutlet weak var tableView: UITableView!
|
@IBOutlet weak var view_container: UIView!
|
@IBOutlet weak var cons_bottom: NSLayoutConstraint!
|
@IBOutlet weak var cons_tableHei: NSLayoutConstraint!
|
|
private var items = [String]()
|
private var clouse:((String)->Void)!
|
private var selectIndex:IndexPath?
|
|
override func awakeFromNib() {
|
super.awakeFromNib()
|
cons_bottom.constant = -JQ_ScreenW
|
alpha = 0
|
cons_tableHei.constant = 0
|
backgroundColor = .clear
|
view_container.backgroundColor = .white.withAlphaComponent(0.9)
|
tableView.register(UINib(nibName: "ChooseOptTitleTCell", bundle: nil), forCellReuseIdentifier: "_ChooseOptTitleTCell")
|
tableView.delegate = self
|
tableView.dataSource = self
|
tableView.separatorStyle = .none
|
layoutIfNeeded()
|
}
|
|
static func show(title:String,contents:[String],clouse:@escaping (String)->Void){
|
let titleView = ChooseOptTitleView.jq_loadNibView()
|
titleView.label_title.text = title
|
titleView.items = contents
|
titleView.clouse = clouse
|
sceneDelegate?.window?.addSubview(titleView)
|
titleView.frame = sceneDelegate?.window?.frame ?? .zero
|
|
titleView.cons_bottom.constant = 0
|
titleView.alpha = 1
|
titleView.cons_tableHei.constant = Double(contents.count) * 61
|
UIView.animate(withDuration: 0.5) {
|
titleView.layoutIfNeeded()
|
}
|
}
|
|
override func layoutSubviews() {
|
super.layoutSubviews()
|
view_container.jq_cornerPartWithShadow(byRoundingCorners: [.topLeft,.topRight], radii: 20)
|
}
|
|
@IBAction func cancelAction(_ sender: UIButton) {
|
hidden()
|
}
|
|
@IBAction func completeAction(_ sender: UIButton) {
|
|
guard selectIndex != nil else{
|
alertError(msg: "请选择举报内容");return
|
}
|
|
CommonAlertView.show(title: "提示", content: "确认举报该提问?") {[weak self] state in
|
guard let weakSelf = self else { return }
|
|
if state{
|
weakSelf.clouse(weakSelf.items[weakSelf.selectIndex!.row])
|
weakSelf.hidden()
|
}
|
}
|
}
|
|
private func hidden(){
|
cons_bottom.constant = -JQ_ScreenW
|
cons_tableHei.constant = 0
|
UIView.animate(withDuration: 0.6) {
|
self.alpha = 0
|
self.layoutIfNeeded()
|
} completion: { _ in
|
self.removeFromSuperview()
|
}
|
}
|
}
|
|
extension ChooseOptTitleView:UITableViewDelegate{
|
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
selectIndex = indexPath
|
tableView.reloadData()
|
}
|
}
|
|
extension ChooseOptTitleView:UITableViewDataSource{
|
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
let cell = tableView.dequeueReusableCell(withIdentifier: "_ChooseOptTitleTCell") as! ChooseOptTitleTCell
|
cell.label_title.text = items[indexPath.row]
|
|
if indexPath == selectIndex{
|
cell.label_title.textColor = UIColor(hexString: "#8AAE65")
|
cell.img_choose.image = UIImage(named: "icon_choose_small_s")
|
}else{
|
cell.label_title.textColor = UIColor(hexString: "#5C5C5C")
|
cell.img_choose.image = UIImage(named: "icon_choose_small")
|
}
|
return cell
|
}
|
|
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
return items.count
|
}
|
|
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
|
return 61
|
}
|
}
|