简体   繁体   English

当我触摸 UIVIew 时,CALayer/UIView 崩溃

[英]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.这是堆栈。

在此处输入图像描述

You can't use a UIView object to be the delegate of a layer other than its own layer.您不能使用UIView object 作为其自身图层以外的图层的代表。 Its stated here .here说明。 You will need to assign some other object as its delegate.您需要指定其他一些 object 作为其代表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM