2015-06-20 124 views
1

所以我第一次正確地設置了一個UIView圖層的陰影(它顯示完全正常),但是當我嘗試更改顏色時(沒有別的,只是layer.shadowColor)它不會更新風景。它仍然顯示原始的顏色。我已經試過layer setNeedsDisplay沒有任何運氣。CALayer shadowColor not changing

self.profileIconShadow.layer.cornerRadius = self.profileIcon.frame.size.height/2; 
self.profileIconShadow.layer.shadowColor = [UIColor blackColor].CGColor; 
self.profileIconShadow.layer.shadowOpacity = 1.0f; 
self.profileIconShadow.layer.shadowRadius = self.profileIcon.frame.size.width * .025; 
self.profileIconShadow.layer.shadowOffset = CGSizeZero; 

// if ([entry[@"isInactive"] boolValue]) { // Original 
if (true) { // Overrode temporarily to test it out 
    self.profileIconShadow.layer.shadowColor = [UIColor redColor].CGColor; 
    [self.profileIconShadow.layer setNeedsDisplay]; 
} 

影子得到正確設置爲所需要的第一次。但後來我嘗試改變它仍然保持黑色而不是變紅的顏色。

這是它應該如何看。

編輯#2:我注意到,如果我在第一次製作陰影時註釋掉黑色,它會在稍後變成紅色。我能不能多次更換shadowColor

+0

試了一下,可以正常使用到我..你確定你沒有把顏色分配給'self.profileIconShadow.layer.shadowColor'某處SE? – 0yeoj

+0

@ 0yeoj我只有代碼,我先將它設置爲黑色,然後再變爲紅色。 – Victor

回答

1

我昨晚想你的代碼,我還送的開啓和關閉出你的代碼之前,我去睡覺..哈哈動畫..

問題:Can I not change shadowColor multiple times?,當然你也可以.. ;)

爲什麼你的層沒有更新的,也許它不是在主線程中執行的唯一可能的原因,以確保試試這個:

if ([entry[@"isInactive"] boolValue]) 
{ // Original 
    dispatch_async(dispatch_get_main_queue(), ^{ 

     self.profileIconShadow.layer.shadowColor = [UIColor redColor].CGColor; 

     [self.profileIconShadow.layer setNeedsDisplay]; 

    } 
}