我正在尝试使用CALayer
和CGContextStrokePath(context)
来绘制签名,但是它仅在iOS 12中因以下错误而棘手崩溃:
malloc:已释放对象0x1196538c8的校验和不正确:可能 释放后修改。 损坏的值:0x4069e00000000000 (899,0x17190b000)malloc:***在malloc_error_break中设置一个断点进行调试
代码段:
- (void)drawLayer:(CATiledLayer *)layer inContext:(CGContextRef)contx {
if (layer == canvasLayer) {
//we don't want this to fire after the background layer update
//and after the path has been released
if (!touching) return;
CGContextAddPath(contx, path);
CGContextSetLineWidth(contx, 7.0f);
CGContextStrokePath(contx);
}
else if (layer == bckLayer) {
CGContextSaveGState(contx);
CGContextTranslateCTM(contx, 0, backgroundLayer.bounds.size.height);
CGContextScaleCTM(contx, 1.0, -1.0);
CGImageRef ref = cacheImage.CGImage;
CGContextDrawImage(contx, backgroundLayer.bounds, ref);
CGContextRestoreGState(ctx);
}
}