0
我有一個UIView子類,它實例化其圖層的三個兄弟子圖層。其中兩個子圖層將其內容設置爲圖像文件;並且第三張圖中有一張畫在重新排序子層沒有影響
- (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx
方法。問題是我的繪圖層總是出現在圖像層後面。我嘗試重新排序子層數組並改變子層的zPosition屬性無濟於事。我錯過了什麼?
- (void)setupLayers
{
CALayer *rootLayer = [self layer];
_meterLayer = [CALayer layer];
[_meterLayer setContents:(id)[[UIImage imageNamed:@"HealthMeterRadial60x60.png"] CGImage]];
_pointerLayer = [CALayer layer];
[_pointerLayer setContents:(id)[[UIImage imageNamed:@"HealthMeterRadialPointer60x60.png"] CGImage]];
_labelLayer = [CALayer layer];
[self set_labelText:@"Health"];
[rootLayer addSublayer:_meterLayer];
[rootLayer insertSublayer:_pointerLayer above:_meterLayer];
[rootLayer insertSublayer:_labelLayer above:_pointerLayer];
}
而且drawLayerInContext方法:
- (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx
{
if(layer = _labelLayer) {
//draw graphics ... omitted for clarity; works, but always behind images
}
}