2012-08-15 22 views
2

如何將陰影添加到一組CALayer中? 我有一個「FoldingView」類,它支持幾個「SliceView」類。每一個sliceview的圖層都會被一個CATransform3D所使用的透視屬性(.m34 = 1.0/-1000)。如何使用CATransform3D爲一組CALayer添加陰影

如何添加具有良好視覺邏輯的陰影?這是我一直在想的:

  1. 我可以得到每個切片的路徑,並結合這些獲得陰影路徑。

    • 我不知道如何當層使用CATransform3D
    • 它可能在視覺上的工作得到的CALayer的道路,但我怕如果光應該也不會是完全正確來自左上角。
  2. 我可以只申請標準CALayer的陰影所有層

    • 它看起來並不好,由於陰影互相重疊

如果任何人有任何其他建議或知道如何編碼想法編號1我會很高興!這裏是你看到截圖的示例項目的鏈接。

Download zipped application with code

Sample image from application

+0

如果您想降低我的問題,請添加評論。我想知道這個問題有什麼問題! – hfossli 2013-01-21 18:42:26

回答

1

這似乎是工作通緝。這是每個sliceview完成的。

- (UIBezierPath *)shadowPath 
{ 

    if(self.progress == 0 && self.position != VGFoldSliceCenter) 
    { 
     UIBezierPath *path = [UIBezierPath bezierPath]; 
     return path; 
    } 
    else 
    { 
     CGPoint topLeft = pointForAnchorPointInRect(CGPointMake(0, 0), self.bounds); 
     CGPoint topRight = pointForAnchorPointInRect(CGPointMake(1, 0), self.bounds); 
     CGPoint bottomLeft = pointForAnchorPointInRect(CGPointMake(0, 1), self.bounds); 
     CGPoint bottomRight = pointForAnchorPointInRect(CGPointMake(1, 1), self.bounds); 

     CGPoint topLeftTranslated = [self.superview convertPoint:topLeft fromView:self]; 
     CGPoint topRightTranslated = [self.superview convertPoint:topRight fromView:self]; 
     CGPoint bottomLeftTranslated = [self.superview convertPoint:bottomLeft fromView:self]; 
     CGPoint bottomRightTranslated = [self.superview convertPoint:bottomRight fromView:self]; 

     UIBezierPath *path = [UIBezierPath bezierPath]; 

     [path moveToPoint:topLeftTranslated]; 
     [path addLineToPoint:topRightTranslated]; 
     [path addLineToPoint:bottomRightTranslated]; 
     [path addLineToPoint:bottomLeftTranslated]; 
     [path closePath]; 

     return path; 
    } 
}