我在ARC下使用[UIBezierPath CGPath]
和CAShapeLayer
發生了BAD ACCESS錯誤。我嘗試了各種橋接方式,但我不清楚這是否是問題所在。我已隔離崩潰使用makeToPath
方法的結果:在ARC下使用帶有CAShapeLayer的[UIBezierPath CGPath]崩潰
maskLayer = [CAShapeLayer layer];
maskLayer.path = [self makeToPath];
但這不會崩潰:
maskLayer = [CAShapeLayer layer];
maskLayer.path = [self makeFromPath];
有什麼無效與makeToPath
創建的路徑?我計劃使用從和到路徑與CABasicAnimation
一旦我排序這崩潰了。什麼是從UIBezierPath
CGPathRef
s正確的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];
}
UPDATE所以我改變了我的.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;
}
[設備上運行時EXC \ _ARM \ _DA \ _ALIGN錯誤(HTTP的可能重複:// stackoverflow.com/questions/14129785/exc-arm-da-align-error-when-running-on-a-device) –
我使用最後的語法,讓'makeToPath'返回'UIBezierPath *',然後使用'maskLayer。 path = [[self makeToPath] CGPath];',所有的時間。但我也立即使用'maskLayer',例如'[self.view.layer addSublayer:maskLayer]'。在設置'path'後,你用'maskLayer'做了什麼?你能告訴我們嗎? – Rob
@Rob - 我清理了一些代碼,運行了'nap debugger',現在它工作。 –