0
for (CALayer *layer in self.view.layer.sublayers) {
if ([layer isKindOfClass:[CAShapeLayer class]]) {
CAShapeLayer *copy = (CAShapeLayer *)layer;
if ([copy.name isEqualToString:@"datumSideLayer"]) {
//get start position, get height, get width
CGPoint startPos = copy.frame.origin;
float width = copy.frame.size.width;
float height = copy.frame.size.height;
CGPoint startPoint = CGPointMake(startPos.x + (width/2), startPos.y);
CGPoint endPoint = CGPointMake(startPos.x + (width/2), startPos.y + height);
NSLog(@"%.1f:%.1f, %.1f:%.1f", startPoint.x, startPoint.y, endPoint.x, endPoint.y);
[self drawDashedLineFrom:startPoint toEnd:endPoint inView:_thicknessUI];
break;
}
}
}
NSLog輸出爲0.0:0.0, 0.0:0.0
。嵌套CAShapeLayer§獲取來源?
它所嵌套的形狀圖層作爲屬性強烈實例化。但是,我無法抓住框架的原點,寬度或高度。
編輯:進一步挖掘後,我沒有框架設置爲我的CAShapeLayer - 因爲它是由路徑繪製。
但是,我現在怎麼能適應這個,所以它的起源可以從路徑的開始抓取?
[path moveToPoint:CGPointMake(self.view.frame.size.width/2 - _plateLengthPX, tenPercent)]; // datum side start
[path addLineToPoint:CGPointMake(self.view.frame.size.width/2 - capStartWidthPX - rootGapPX, tenPercent)]; // weld(cap) start
[path addLineToPoint:CGPointMake(self.view.frame.size.width/2 - rootGapPX, tenPercent + _plateHeightPX - rootPrepHeightPX)]; // weld(root prep) start
[path addLineToPoint:CGPointMake(self.view.frame.size.width/2 - rootGapPX, tenPercent + _plateHeightPX)]; // weld(root prep) end
[path addLineToPoint:CGPointMake(self.view.frame.size.width/2 - _plateLengthPX, tenPercent + _plateHeightPX)]; // datum side end
[path addLineToPoint:CGPointMake(self.view.frame.size.width/2 - _plateLengthPX, tenPercent + _plateHeightPX/2 + 10)]; // datum side end
[path addLineToPoint:CGPointMake(self.view.frame.size.width/2 - _plateLengthPX + 15, tenPercent + _plateHeightPX/2 + 5)]; // datum side end
[path addLineToPoint:CGPointMake(self.view.frame.size.width/2 - _plateLengthPX - 15, tenPercent + _plateHeightPX/2 - 5)]; // datum side end
[path addLineToPoint:CGPointMake(self.view.frame.size.width/2 - _plateLengthPX, tenPercent + _plateHeightPX/2 - 10)]; // datum side end
_datumLayer = [CAShapeLayer layer];
_datumLayer.name = @"datumSideLayer";
_datumLayer.path = [path CGPath];
_datumLayer.strokeColor = [_lineColor CGColor];
_datumLayer.lineWidth = 2.0;
_datumLayer.fillColor = [_shaderColor CGColor];
[self.view.layer addSublayer:_datumLayer];