问题描述
有没有办法在快速按下按钮后向上而不是向下打开我的表格视图?
当我按下按钮并打开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 (将#修改为@)