Ios 如何获得CAShapeLayer';s帧与它的superview相对?

Ios 如何获得CAShapeLayer';s帧与它的superview相对?,ios,objective-c,uibezierpath,cashapelayer,Ios,Objective C,Uibezierpath,Cashapelayer,有谁能帮我得到CAShapeLayer的框架,它作为一个子层添加到UIImageView中 以下是我的代码: CAShapeLayer *shapeLayer = [[CAShapeLayer alloc] init]; shapeLayer.fillColor = [[UIColor redColor] colorWithAlphaComponent:0.15].CGColor; shapeLayer.strokeColor = [UIColor redColor].CGColor; sha

有谁能帮我得到CAShapeLayer的框架,它作为一个子层添加到UIImageView中

以下是我的代码:

CAShapeLayer  *shapeLayer = [[CAShapeLayer alloc] init];
shapeLayer.fillColor = [[UIColor redColor] colorWithAlphaComponent:0.15].CGColor;
shapeLayer.strokeColor = [UIColor redColor].CGColor;
shapeLayer.lineWidth = 3.0;
shapeLayer.zPosition = 1;
[_imgBackground.layer insertSublayer:shapeLayer atIndex:1];

UIBezierPath *path = [UIBezierPath bezierPath];
[path moveToPoint:CGPointMake(50, 50)]; // left top point of rack
[path addLineToPoint:CGPointMake(100, 50)]; // right top point of rack
[path addLineToPoint:CGPointMake(100, 100)]; // right bottom point of rack
[path addLineToPoint:CGPointMake(50, 100)]; // left bottom point of rack
[path closePath]; // closing rectangle/path

shapeLayer.path = path.CGPath;
据我所知,我们可以从以下行获得帧:

CGRect bounds = CGPathGetBoundingBox(shapeLayer.path);
但它只根据
self.view

我希望它的框架符合UIImageView


提前谢谢。

我从詹姆斯的评论中得到了答案。以下行保存了我的一天:

CGRect bounds = [self.view convertRect:CGPathGetBoundingBox(shapeLayer.path) toView:_imgBackground];

参考资料。

我从詹姆斯的评论中得到了答案。以下行保存了我的一天:

CGRect bounds = [self.view convertRect:CGPathGetBoundingBox(shapeLayer.path) toView:_imgBackground];

参考资料。

您的情况如何?检查我的ans并让我知道..尝试使用CALayer。您可以使用您的情况吗?检查我的ans并让我知道..尝试使用CALayer。您可以使用