【发布时间】:2013-01-22 19:19:00
【问题描述】:
在 ARC 下使用 [UIBezierPath CGPath] 和 CAShapeLayer 时遇到 BAD ACCESS 错误。我尝试过以各种方式进行桥接,但我不清楚这是否是问题所在。我已将崩溃隔离为使用 makeToPath 方法的结果:
maskLayer = [CAShapeLayer layer];
maskLayer.path = [self makeToPath];
但这不会崩溃:
maskLayer = [CAShapeLayer layer];
maskLayer.path = [self makeFromPath];
makeToPath 创建的路径是否有问题?一旦我解决了这个崩溃,我计划使用带有CABasicAnimation 的 from 和 to 路径。来自UIBezierPath 的CGPathRefs 的正确ARC 桥接是什么?
-(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;
我还尝试让我的方法根据答案 here(如下所示)返回一个 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;
}
【问题讨论】:
-
我一直使用最后的语法,让
makeToPath返回UIBezierPath *,然后使用maskLayer.path = [[self makeToPath] CGPath];。但我也立即使用maskLayer,例如[self.view.layer addSublayer:maskLayer]。设置path后,你在用maskLayer做什么?你能告诉我们吗? -
@Rob - 我清理了一些代码,运行了
nap debugger,现在它可以工作了。
标签: ios core-animation uibezierpath cashapelayer