代码拉取完成,页面将自动刷新
//
// RPopDownLIstView.swift
// LZStaff
//
// Created by ray on 2018/11/19.
// Copyright © 2018年 ray. All rights reserved.
//
import UIKit
class RPopDownListView: UIView {
/// 背景
private var bgView:UIView!
private var fromPoint: CGPoint!
var isRouting = false
var dataSource:[Dictionary<String,Any>]!
var selectItemHandler: (((Dictionary<String,Any>)->())?)
lazy var tableView:UITableView = {
let tableView = UITableView.init(frame: .zero, style: .plain)
tableView.showsVerticalScrollIndicator = false
tableView.showsHorizontalScrollIndicator = false
tableView.separatorStyle = .none
tableView.bounces = false
tableView.separatorInset = UIEdgeInsets.init(top: 0, left: 0, bottom: 0, right: 0)
tableView.register(UINib.init(nibName: "RPopDownListCell", bundle: nil), forCellReuseIdentifier: "RPopDownListCell")
return tableView
}()
init(_ point: CGPoint,_ parentVC: ViewController?,_ array:[Dictionary<String,Any>]) {
super.init(frame: RScreen)
self.fromPoint = point
self.dataSource = array
bgView = UIView.init(frame: RScreen)
bgView.backgroundColor = UIColor.black
bgView.alpha = 0
let tapBgView = UITapGestureRecognizer.init(target: self, action: #selector(tapBgViewAction))
bgView.addGestureRecognizer(tapBgView)
self.configTBView()
if let tmpVC = parentVC{
tmpVC.view.addSubview(bgView)
tmpVC.view.addSubview(tableView)
}else{
currentWindow?.rootViewController?.view.addSubview(bgView)
currentWindow?.rootViewController?.view.addSubview(tableView)
}
self.showView()
}
/// 配置tableview
func configTBView(){
tableView.frame = CGRect.init(x: 0, y: fromPoint.y+64, width: RScreenW, height: 50)
tableView.delegate = self
tableView.dataSource = self
self.addSubview(tableView)
}
@objc private func cancelAction() {
DispatchQueue.main.async {
self.hideView()
}
}
@objc func tapBgViewAction(){
DispatchQueue.main.async {
self.hideView()
}
}
@objc private func confirmAction() {
DispatchQueue.main.async {
self.hideView()
}
}
private func showView() {
var height = RScreenH-64-self.fromPoint.y
CGFloat(self.dataSource.count * 50) > height ? (height = RScreenH-64-self.fromPoint.y-20) : (height = CGFloat(self.dataSource.count * 50))
UIView.animate(withDuration: 0.3, animations: {
self.bgView.alpha = 0.5
self.tableView.alpha = 1
self.tableView.frame = CGRect.init(x: 0, y: self.fromPoint.y+64, width: RScreenW, height: height)
}) { (flag) in
}
}
@objc private func hideView() {
UIView.animate(withDuration: 0.3, animations: {
self.bgView.alpha = 0
self.tableView.alpha = 0
self.tableView.frame = CGRect.init(x: 0, y: self.fromPoint.y+64, width: RScreenW, height: 50)
}) { (flag) in
self.tableView.frame = CGRect.init(x: 0, y: self.fromPoint.y+64, width: RScreenW, height: 50)
self.bgView.removeFromSuperview()
self.tableView.removeFromSuperview()
self.removeFromSuperview()
}
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
extension RPopDownListView: UITableViewDelegate,UITableViewDataSource{
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return dataSource.count
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 50
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)
if let handler = selectItemHandler{
handler(self.dataSource[indexPath.row])
}
self.hideView()
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "RPopDownListCell", for: indexPath) as! RPopDownListCell
cell.configModel(flag:self.isRouting ,dic: self.dataSource[indexPath.row])
return cell
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。