Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios tableView上的程序浮动按钮_Ios_Swift_Uitableview_Floating Action Button - Fatal编程技术网

Ios tableView上的程序浮动按钮

Ios tableView上的程序浮动按钮,ios,swift,uitableview,floating-action-button,Ios,Swift,Uitableview,Floating Action Button,我试图在tableViewController上创建一个浮动按钮,到目前为止,我的代码是这样的,但是按钮固定在两个单元格之间,所以它不是浮动的 let button = UIButton(frame: CGRect(x: 150, y: 550, width: 75, height: 75)) button.backgroundColor = .yellow button.setTitle("To Jobs", for: .normal) button.addTarget(self, actio

我试图在tableViewController上创建一个浮动按钮,到目前为止,我的代码是这样的,但是按钮固定在两个单元格之间,所以它不是浮动的

let button = UIButton(frame: CGRect(x: 150, y: 550, width: 75, height: 75))
button.backgroundColor = .yellow
button.setTitle("To Jobs", for: .normal)
button.addTarget(self, action: #selector(buttonAction), for: .touchUpInside)
self.view.addSubview(button)
这是因为UITableViewController中的self.view=UITableView,所以需要实现scrollViewDidScroll


您可以将按钮添加到窗口中,使其位于tableView的顶部。您所说的按钮固定在两个单元格之间,使其不浮动是什么意思??你是说滚动表格视图时按钮会移动吗?参考这个问题,它可能会对你有所帮助
class TableViewController: UITableViewController {

    let button = UIButton(frame: CGRect(x: 150, y: 550, width: 75, height: 75))

    override func viewDidLoad() {
        super.viewDidLoad()

        button.backgroundColor = .yellow
        button.setTitle("To Jobs", for: .normal)
        self.view.addSubview(button)

    }

    override func scrollViewDidScroll(_ scrollView: UIScrollView) {

        button.frame.origin.y = 550 + scrollView.contentOffset.y
    }

}