【发布时间】:2017-03-12 01:31:58
【问题描述】:
我试图在 UITableView 中居中自定义视图,它工作正常,但是当我滚动时它不会更新到 tableview 的中心,它只是停留在顶部。这是我的代码:
let customView = UIView(frame: CGRect(x: 0, y: 0, width: 150, height: 75))
customView.backgroundColor = UIColor(red: 0/255, green: 174/255, blue: 250/255, alpha: 1.0)
let label = UILabel(frame: CGRect(x: customView.frame.midX, y: customView.frame.midY, width: 150, height: 75))
label.text = "Text"
label.textAlignment = .center
label.font = UIFont(name: "HelveticaNeue-Light", size: 18)
label.textColor = UIColor.white
customView.addSubview(label)
label.center = customView.center
customView.layer.cornerRadius = 4.0
self.view.addSubview(customView)
customView.center = CGPoint(x: self.tableView.bounds.width/2, y: self.tableView.bounds.height/2)
UIView.animate(withDuration: 1.5, animations: {
customView.alpha = 0.0
}) { (success: Bool) in
customView.removeFromSuperview()
}
关于如何完成这项工作的任何想法?谢谢。
【问题讨论】:
-
该代码中的
self是什么?您希望发生的事情没有发生?
标签: swift uitableview uiview scrollview uiviewanimation