BrokerageSheetView.swift 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. //
  2. // BrokerageSheetView.swift
  3. // ADHTuanCan
  4. //
  5. // Created by 敖德亨 on 2023/11/8.
  6. //
  7. import UIKit
  8. class BrokerageSheetView: UIView {
  9. @IBOutlet weak var blackView: UIView!
  10. @IBOutlet weak var tableView: UITableView!
  11. @IBOutlet weak var viewHeight: NSLayoutConstraint!
  12. var dataSource : [BrokerageListItemModel]?
  13. override func awakeFromNib() {
  14. super.awakeFromNib()
  15. self.tableView.register(withType: BrokerageCell.self)
  16. self.tableView.ly_emptyView = LYEmptyView.emptyActionView(with: UIImage.init(named: "暂无数据"), titleStr: "暂无数据", detailStr: "", btnTitleStr: "", btnClick: {[weak self] in
  17. })
  18. }
  19. func configModel(dataSource : [BrokerageListItemModel]?){
  20. self.dataSource = dataSource
  21. if (self.dataSource?.count ?? 0) > 0{
  22. if (self.dataSource?.count ?? 0) > 4{
  23. self.viewHeight.constant = 204 - 60 + 80 * 5
  24. }else{
  25. self.viewHeight.constant = CGFloat(204 - 60 + 80 * (self.dataSource?.count ?? 0))
  26. }
  27. }else{
  28. self.viewHeight.constant = 330
  29. }
  30. self.tableView.reloadData()
  31. }
  32. public func show(){
  33. kAppDelegateWindow.addSubview(self)
  34. self.blackView.alpha = 0
  35. self.frame = CGRect.init(x: 0, y: kSCREEN_HEIGHT, width: kSCREEN_WIDTH, height: kSCREEN_HEIGHT)
  36. UIView.animate(withDuration: 0.5) {
  37. self.frame = CGRect.init(x: 0, y: 0, width: kSCREEN_WIDTH, height: kSCREEN_HEIGHT)
  38. self.layoutIfNeeded()
  39. }
  40. DELAY(0.5) {
  41. self.blackView.alpha = 0.3
  42. }
  43. }
  44. /// 隐藏
  45. public func hidden(){
  46. self.blackView.alpha = 0
  47. UIView.animate(withDuration: 0.5) {
  48. self.frame = CGRect.init(x: 0, y: kSCREEN_HEIGHT, width: kSCREEN_WIDTH, height: kSCREEN_HEIGHT)
  49. self.layoutIfNeeded()
  50. }
  51. DELAY(0.5) {
  52. self.removeFromSuperview()
  53. }
  54. }
  55. @IBAction func backViewAction(_ sender: UIButton) {
  56. self.hidden()
  57. }
  58. @IBAction func cancelAction(_ sender: UIButton) {
  59. self.hidden()
  60. }
  61. }
  62. extension BrokerageSheetView : UITableViewDelegate,UITableViewDataSource{
  63. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  64. return self.dataSource?.count ?? 0
  65. }
  66. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  67. let cell = tableView.dequeueReusableCell(withIdentifier: "BrokerageCell") as! BrokerageCell
  68. cell.configModel(model: self.dataSource![indexPath.row])
  69. return cell
  70. }
  71. func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
  72. return 0.01
  73. }
  74. func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  75. }
  76. func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
  77. return 0.01
  78. }
  79. }