UITableView header cannot work with UIViewAnimationOptions.Repeat
I want the title of the table view to blink, but it doesn't work.
func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let headerView = UIView()
headerView.backgroundColor = UIColor.redColor()
UIView.animateWithDuration(
0.3, delay: 0,
options: UIViewAnimationOptions.Repeat,
animations: { headerView.alpha = 0 },
completion: nil)
return headerView
}
+3
source to share
4 answers
You must set UIView.setAnimationsEnabled(true);
before calling the animation like this:
func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let headerView = UIView()
headerView.backgroundColor = UIColor.redColor()
UIView.setAnimationsEnabled(true)
UIView.animateWithDuration(
0.3, delay: 0,
options: UIViewAnimationOptions.Repeat,
animations: { headerView.alpha = 0 },
completion: nil)
return headerView
}
+2
source to share
Try to move the animation block to the display method of the delegate `displayHeaderView which will work
Swift 3
func tableView(_ tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int) {
UIView.animate(
withDuration: 0.3, delay: 0,
options: UIViewAnimationOptions.repeat,
animations: { view.alpha = 0
},
completion: nil)
}
0
source to share