关于CALayer导致的crash问题
关于 导致 Crash 问题
2023-09-11 14:18:57 时间
push到一个页面进行绘图时,设置如下:
CALayer * layer = [CALayer layer]; layer.frame = CGRectMake(0, 0, 300, 300); layer.delegate = self; [layer setNeedsDisplay]; [self.view.layer addSublayer:layer];
-(void) drawLayer: (CALayer*) layer inContext: (CGContextRef) context;
设置delegate后,点击返回按钮时会奔溃。没有push直接绘制的时候就没有问题。
设置其delegate为uiview类型实例。会导致程序crash。
关于这一点,苹果官方在文档中已有说明。解决办法:
he lightest-wight solution would be to create a small helper class in the the file as the UIView that's using the CALayer: In MyView.h @interface MyLayerDelegate : NSObject . . . @end In MyView.m @implementation MyLayerDelegate - (void)drawLayer:(CALayer*)layer inContext:(CGContextRef)ctx { . . . } @end Just place those at the top of your file, immediately below the #import directives. That way it feels more like using a "private class" to handle the drawing (although it isn't -- the delegate class can be instantiated by any code that imports the header).
没怎么看懂:
直接继承CALayer或者CAShapeLayer重写:
- (void)drawInContext:(CGContextRef)ctx
就可以
相关文章
- 关于git拉取项目时,报RPC failed; curl 18 transfer closed with outstanding read data remaining错的解决方案
- 面试中可能会被问到的几个关于“委托”的问题
- SQL SERVER中关于OR会导致索引扫描或全表扫描的浅析
- 关于MBR、GPT以及BIOS引导模式区分
- 关于Qt数据库相关开发的一些经验总结
- 关于 Orbeon form PE 版本使用 JavaScript Embedding API 的一个例子
- 关于 SAP UI5 应用 ui5.yaml 里的 paths 映射问题
- 关于C++ const 的全面总结
- 【问题解决】关于MySQL在上行锁并更新数据之后导致死锁问题解决
- 关于 Cypress 同界面元素交互的讨论