如何解决按下按钮后向上打开表格视图很热?
有没有办法在快速按下按钮后向上而不是向下打开我的表格视图?
当我按下按钮并打开TableViewControler时,下面没有足够的空间来显示tableview中所有可能的选项,因此,我想知道有没有办法向上打开tableview?
附上问题的截图如下:screenshot
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
}
override func viewDidLoad() {
overrideUserInterfaceStyle = .light
super.viewDidLoad()
tableView.delegate = self
tableView.dataSource = self
tableView.register(CellClass.self,forCellReuseIdentifier: "Cell")
}
//MARK: What happens when you click "When"
func addTransparentView(frames: CGRect) {
let window = UIApplication.shared.keyWindow
transparentView.frame = window?.frame ?? self.view.frame
self.view.addSubview(transparentView)
tableView.frame = CGRect(x: frames.origin.x,y: frames.origin.y + frames.height,width: frames.width,height: 0)
self.view.addSubview(tableView)
tableView.layer.cornerRadius = 15
transparentView.backgroundColor = UIColor.black.withAlphaComponent(0.9)
tableView.reloadData()
let tapgesture = UITapGestureRecognizer(target: self,action: #selector(removeTransparentView))
transparentView.addGestureRecognizer(tapgesture)
transparentView.alpha = 0
UIView.animate(withDuration: 0.4,delay: 0.0,usingSpringWithdamping: 1.0,initialSpringVeLocity: 1.0,options: .curveEaseInOut,animations: {
self.transparentView.alpha = 0.5
self.tableView.frame = CGRect(x: frames.origin.x,y: frames.origin.y + frames.height + 5,height: CGFloat(self.dataSource.count * 50))
},completion: nil)
}
@objc func removeTransparentView() {
let frames = selectedButton.frame
UIView.animate(withDuration: 0.4,animations: {
self.transparentView.alpha = 0
self.tableView.frame = CGRect(x: frames.origin.x,height: 0)
},completion: nil)
}
@IBAction func selectTimeButtonpressed(_ sender: Any) {
dataSource = ["Now ?","THIS EVENING ?","ANYTIME TODAY ?","IN A FEW HOURS ⏳","SOMETIME TOMORROW ✨","TOMORROW EVENING ?","OVER THE WEEKEND ?"]
selectedButton = selectTimeButton
addTransparentView(frames: selectTimeButton.frame)
timeDetails = selectedButton.titleLabel?.text ?? "nothing is here in timedetails"
print(timeDetails,"from selectTImeBUttonpressed")
}
extension WhatDoYouWannaDoViewController {
func tableView(_ tableView: UITableView,numberOfRowsInSection section: Int) -> Int {
return dataSource.count
}
func tableView(_ tableView: UITableView,cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell",for: indexPath)
cell.textLabel?.text = dataSource[indexPath.row]
cell.backgroundColor = .white
cell.textLabel?.font = UIFont(name: "ContrailOne-Regular",size: 20)!
return cell
}
func tableView(_ tableView: UITableView,heightForRowAt indexPath: IndexPath) -> CGFloat {
return 50
}
func tableView(_ tableView: UITableView,didSelectRowAt indexPath: IndexPath) {
selectedButton.setTitle(dataSource[indexPath.row],for: .normal)
removeTransparentView()
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。