gpt4 book ai didi

ios - 如何让 CAShapeLayer 的框架面对它的 super View ?

转载 作者:行者123 更新时间:2023-11-28 21:20:26 25 4
gpt4 key购买 nike

任何人都可以帮助我获取作为 SubLayer 添加到 UIImageView 中的 CAShapeLayer 的框架吗?

以下是我的代码:

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。

提前致谢。

最佳答案

好吧,我从 James 的评论中得到了答案。下面一行挽救了我的一天:

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

来自 this引用。

关于ios - 如何让 CAShapeLayer 的框架面对它的 super View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39992978/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com