2016-10-28 38 views
0

我有一个tableview,当我收到一条消息它重新加载,然后我希望接收消息的单元改变它的背景颜色一秒钟,然后改变返回到之前的颜色(具有或不具有进/出褪色)如何使用Swift淡入/淡出tableviewcell的背景色

我知道哪个小区接收到的消息与该代码:

if changeCell == indexPath.row { 

     cell.viewCell.backgroundColor = UIColor.red 

    } 

viewCell是一个视图我把在小区改变的背景颜色细胞更容易

我搜索一个lo吨找出来,但每个解决方案开始UIView.animate ....当我把它改变了我的桌面外的视图的颜色

+0

你是我们ing xcode 8和swift 3.0? –

+0

@HimanshuMoradiya是 –

回答

2

UIView动画家庭的方法是你想要的。

​​
+0

嗨,谢谢你的回答,但所有细胞都在淡入/淡出 –

0

添加这些选项动画:

  • UIViewAnimationOptions.transitionCrossDissolve
  • UIViewAnimationOptions.allowAnimatedContent

例子:

fileprivate var color1 = UIColor.clear 
fileprivate var color2 = UIColor.red 
fileprivate func animateCell(_ cell: UITableViewCell) { 

    UIView.animate(withDuration: 1.0, delay: 0.0, options: [.transitionCrossDissolve, .allowAnimatedContent], animations: { 
     cell.contentView.backgroundColor = self.color2 
    }) { (_) in 
     UIView.animate(withDuration: 1.0, animations: { 
      cell.contentView.backgroundColor = self.color1 
     }) 
    } 

}