No *_*ing 5 core-animation cashapelayer ios uibezierpath
我得到使用BAD访问错误[UIBezierPath CGPath]与CAShapeLayer下ARC.我尝试过以各种方式进行桥接,但我不清楚这是不是问题.我已经将崩溃隔离到使用makeToPath方法的结果:
maskLayer = [CAShapeLayer layer];
maskLayer.path = [self makeToPath];
Run Code Online (Sandbox Code Playgroud)
但这不会崩溃:
maskLayer = [CAShapeLayer layer];
maskLayer.path = [self makeFromPath];
Run Code Online (Sandbox Code Playgroud)
是否存在由创建的路径无效的内容makeToPath?我打算一次性使用from和to path,CABasicAnimation我将这个崩溃排除在外.什么是正确的ARC桥为CGPathRef从s 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];
}
Run Code Online (Sandbox Code Playgroud)
更新所以我根据下面的答案更改了我的.h文件,但我仍然遇到了崩溃
-(CGPathRef)makeToPath CF_RETURNS_RETAINED;
-(CGPathRef)makeFromPath CF_RETURNS_RETAINED;
Run Code Online (Sandbox Code Playgroud)
我也尝试让我的方法UIBezierPath在这里回答一个实例(如下所示).仍然没有成功.有人想给我一个关于如何解决这个问题的长篇解释吗?
maskLayer.path = [[self makeToPath] CGPath];// CRASHES
morph.toValue = CFBridgingRelease([[self makeToPath] CGPath]);// CRASHES
Run Code Online (Sandbox Code Playgroud)
-(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;
}
Run Code Online (Sandbox Code Playgroud)
问题是返回CGPath.返回的值是CGPathRef,ARC未涵盖该值.该UIBezierPath方法结束后,您创建被释放.因此也释放了CGPathRef.您可以指定源注释以让ARC知道您的意图:
在.h文件中:
-(CGPathRef)makeToPath CF_RETURNS_RETAINED;
-(CGPathRef)makeFromPath CF_RETURNS_RETAINED;
Run Code Online (Sandbox Code Playgroud)