在 ARC 下使用[UIBezierPath CGPath]
with 时出现 BAD ACCESS 错误。CAShapeLayer
我尝试过以各种方式进行桥接,但我不清楚这是否是问题所在。我已将崩溃隔离为使用该makeToPath
方法的结果:
maskLayer = [CAShapeLayer layer];
maskLayer.path = [self makeToPath];
但这不会崩溃:
maskLayer = [CAShapeLayer layer];
maskLayer.path = [self makeFromPath];
由 创建的路径是否有无效的地方makeToPath
?一旦我解决了这个崩溃问题,我计划使用from和to路径。s fromCABasicAnimation
的正确 ARC 桥接是什么?CGPathRef
UIBezierPath
-(CGPathRef)makeToPath
{
UIBezierPath* triangle = [UIBezierPath bezierPath];
[triangle moveToPoint:CGPointZero];
[triangle addLineToPoint:CGPointMake(self.view.frame.size.width,0)];
[triangle addLineToPoint:CGPointMake(0, self.view.frame.size.height)];
[triangle closePath];
return [triangle CGPath];
}
-(CGPathRef)makeFromPath
{
UIBezierPath*rect = [UIBezierPath bezierPathWithRect:self.view.frame];
return [rect CGPath];
}
更新所以我根据下面的答案更改了我的 .h 文件,但我仍然遇到崩溃
-(CGPathRef)makeToPath CF_RETURNS_RETAINED;
-(CGPathRef)makeFromPath CF_RETURNS_RETAINED;
我还尝试让我的方法根据此处UIBezierPath
的答案返回一个实例(如下所示)。仍然没有成功。有人想给我关于如何解决这个问题的详细解释吗?
maskLayer.path = [[self makeToPath] CGPath];// CRASHES
morph.toValue = CFBridgingRelease([[self makeToPath] CGPath]);// CRASHES
-(UIBezierPath*)makeToPath
{
UIBezierPath* triangle = [UIBezierPath bezierPath];
[triangle moveToPoint:CGPointZero];
[triangle addLineToPoint:CGPointMake(self.view.frame.size.width,0)];
[triangle addLineToPoint:CGPointMake(0, self.view.frame.size.height)];
[triangle closePath];
return triangle;
}