[英]Swift Animate Background not working from a collection view cell
我有這段代碼可以更改集合視圖單元格的背景,但是由於某些原因,它無法正常工作。
UIView.animateWithDuration(2, animations: {() -> Void in
self.backgroundColor = UIColor.blackColor()
})
你能幫我么?
我認為屬性backgroundColor
對於該單元格不是可動畫的。 您真正想要的是從一種顏色混合到另一種顏色。
一種解決方案是設置backgroundView
的顏色並為其alpha
設置動畫。 您還可以插入自己的視圖作為背景,並以相反的方向為其Alpha設置動畫以創建更改。
另一個解決方案是降低到layer
級別並為圖層背景色設置動畫。
UIView.animateWithDuration(2, animations: {() -> Void in
self.layer.backgroundColor = UIColor.blackColor().CGColor
})
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.