我的应用程序出现一些问题,该问题不断间歇地崩溃。下面的代码在一个以CATiledLayer为后盾的UIView中:
- (UIBezierPath *)path
{
if(_path == nil){
_path = [UIBezierPath bezierPath];
CGFloat lineWidth = 5;
[_path setLineWidth:lineWidth];
[_path setLineJoinStyle:kCGLineJoinRound];
[_path setLineCapStyle:kCGLineCapRound];
[_path moveToPoint:CGPointMake(100, 100)];
[_path addLineToPoint:CGPointMake(200,200)];
[_path addLineToPoint:CGPointMake(150,200)];
[_path addLineToPoint:CGPointMake(50,400)];
_path closePath];
return _path;
}
return _path;
}
- (void)drawRect:(CGRect)rect
{
[[UIColor colorWithRed:0.1 green:0.1 blue:1 alpha:0.45] setStroke];//sets stroke color in current context
[self.path stroke];
}
我收到以下错误代码:
Single stepping until exit from function _ZN2CG4Path15apply_transformERK17CGAffineTransform, which has no line number information.
发生错误时似乎没有任何模式。似乎在进行滚动或缩放时可能会发生。有时在我缩放/滚动时会崩溃。有时,我可以缩放一段时间,直到崩溃。
我知道在iOS4之前,UIKit不是线程安全的,并且不能与CATiledLayers一起使用。请参阅tech note。我的问题(我认为)似乎是线程问题。当然可以怪UIKit吗?
最佳答案
尝试将path
属性设置为atomic
。
另外,您可能应该将drawRect
修改为以下内容:
- (void)drawRect:(CGRect)rect
{
[[UIColor colorWithRed:0.1 green:0.1 blue:1 alpha:0.45] setStroke];//sets stroke color in current context
@synchronized(self) {
[self.path stroke];
}
}
关于iphone - CATitledLayer的间歇性EXC_BAD_ACCESS异常,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/9423079/