2012-02-17 57 views
9

我有下面的菜單樣式佈局,模仿Facebook。我想在下面的左側有一個陰影,但是我使用的圖層陰影使得應用程序LAGGY成爲可能。我一直無法找到一個好的替代解決方案。有沒有人有創建不影響應用程序性能的陰影的替代方法?iOS:創建一個有偏色陰影

[self.navController.view.layer setShadowOffset:CGSizeMake(0, 1)]; 
[self.navController.view.layer setShadowColor:[[UIColor darkGrayColor] CGColor]]; 
[self.navController.view.layer setShadowRadius:8.0]; 
[self.navController.view.layer setShadowOpacity:0.8]; 

上面的代碼是我目前正在使用,導致應用性能問題的代碼。

以下圖片是我想實現的,但不必使用上面的代碼。

enter image description here

回答

10

這應有助於指定陰影路徑,例如,

CGPathRef shadowPath = [UIBezierPath bezierPathWithRect:self.navController.view.layer.bounds].CGPath; 
[self.navController.view.layer setShadowPath:shadowPath] 

按照CALayer documentation 「通常指定明確的路徑提高了渲染性能。」

+0

真棒!這幫助了很多,但我注意到一點點的表現仍然不壞。 – Bot 2012-02-17 22:46:46

0

我自己只會添加一個包含該陰影的UIView作爲子視圖,並在右側視圖動畫時重新定位它。 (例如繪製層或核心顯卡影子)

+0

添加太多視圖會降低性能好友 – 2017-08-31 09:39:44

4

你可以插入意見邊界並設置陰影路徑:

UIEdgeInsets contentInsets = UIEdgeInsetsMake(10, 0, 0, 0); 
CGRect shadowPathExcludingTop = UIEdgeInsetsInsetRect(self.bounds, contentInsets); 
self.layer.shadowPath = [UIBezierPath bezierPathWithRect:shadowPathExcludingTop].CGPath;