[英]CALayer/UIView crashes when I touch the UIVIew
Iam using a custom layer for drawing on my UIView
.我正在使用自定义图层在我的
UIView
上绘图。 And to invalidate and update the layer I need to set my view to be the delegate of my CALayer
.为了使图层无效和更新,我需要将我的视图设置为我的
CALayer
的代表。 When this is done it draws my text correctly but when the view receives touches the app crashes.完成后,它会正确绘制我的文本,但是当视图接收到触摸时,应用程序会崩溃。 What I am a doing wrong?
我做错了什么?
- (void) layoutSubView {
if (drawLayer == nil) {
drawLayer = [[CALayer alloc] init];
[drawLayer setDelegate:self];
[[self layer] addSublayer:drawLayer];
}
[drawLayer setFrame:[self bounds]];
[drawLayer setNeedsDisplay];
}
Above is my code to setup the CALayer, and below is the overridden drawLayer method.上面是我设置 CALayer 的代码,下面是覆盖的 drawLayer 方法。
- (void) drawLayer:(CALayer *)layer
inContext:(CGContextRef)ctx {
if (layer == drawLayer) {
UIGraphicsPushContext(ctx);
[self drawTitle:ctx];
UIGraphicsPopContext();
}
}
Here is the stack.这是堆栈。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.