【问题标题】:Adding a button to bottom of UITableViewController with animation用动画在 UITableViewController 底部添加一个按钮
【发布时间】:2016-09-30 05:38:20
【问题描述】:

我想在 UITableView 的底部添加一个动画按钮。我知道如果我将 tableView 放在 UIViewController 中并在底部留出一点空间,可以做到这一点,但我希望添加按钮“浮动”在 tableView 的底部,在单元格的顶部。

我试过这个:

var addButton: UIButton!

override func viewWillAppear(animated: Bool) {
    self.tableView.reloadData()

    let btn = UIButton(frame: CGRectMake(self.view.frame.size.width/2, -44, 88, 88))
    btn.setImage(UIImage(named: "addList"), forState: .Normal)
    btn.addTarget(self, action: Selector("addList:"), forControlEvents: .TouchUpInside)
    self.tableView.addSubview(btn)
    addButton = btn
    UIView.animateWithDuration(0.1, animations: { () -> Void in
        btn.frame = CGRectMake(self.view.frame.size.width/2, 50, 88, 88)
        self.addButton = btn
        }, completion: nil)
}

但是这不起作用并且没有添加任何按钮。 我试图将按钮放在屏幕中间,但也没有用。 我该怎么做?

【问题讨论】:

  • 我认为你犯了一个小错误。试试这个 CGRectMake(self.view.frame.size.width/2, self.view.frame.size.height-44, 88, 88)
  • @sanman 也没有用
  • 你在 tableview 的页脚部分尝试按钮。
  • 首先尝试设置 btn 的背景颜色以检查 btn 是否存在。您的代码看起来正确。您的代码将 btn 添加到 uitableview 顶部而不是底部,您必须更改按钮框架。

标签: ios swift uitableview uibutton


【解决方案1】:

您可以通过在 tableview 中添加一个单元格来简单地做到这一点。 在里面放一个按钮。

代码:

在视图控制器内部

func tableView(tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
    let header = tableView.dequeueReusableCellWithIdentifier("NextButtonTableViewCell")! as! NextButtonTableViewCell

    return header.contentView
}
func tableView(tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {

    return 50
}

////////////

class NextButtonTableViewCell: UITableViewCell {
   @IBOutlet weak var _btnNext: UIButton! // set outlet 

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-10-31
    • 2023-03-14
    • 1970-01-01
    • 1970-01-01
    • 2015-04-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多