2016-09-30 51 views
0

我想要一個添加按鈕來動畫到我的UITableView的底部。我知道這是可以,如果我把在的tableView一個UIViewController,並在底部留出一點空間來完成,但我想添加按鈕將「漂浮」在的tableView的底部,對細胞的頂部。用動畫添加一個按鈕到UITableViewController的底部

我已經試過這樣:

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) 
} 

然而,這並不工作,並沒有添加按鈕。 我試圖把按鈕放在屏幕中間,也沒有工作。 我該怎麼做?

+0

我想你已經做了一個小錯誤。試試這個CGRectMake(self.view.frame.size.width/2,self.view.frame.size.height-44,88,88)而不是 – sanman

+0

@sanman, t工作要麼 – Marcel

+0

你嘗試按鈕在tableview中的頁腳部分。 –

回答

0

你可以簡單地通過增加的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 

}

相關問題