Reputation: 2535
Iam using a custom layer for drawing on my UIView
. And to invalidate and update the layer I need to set my view to be the delegate of my 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.
- (void) drawLayer:(CALayer *)layer
inContext:(CGContextRef)ctx {
if (layer == drawLayer) {
UIGraphicsPushContext(ctx);
[self drawTitle:ctx];
UIGraphicsPopContext();
}
}
Here is the stack.
Upvotes: 2
Views: 1122
Reputation: 44633
You can't use a UIView
object to be the delegate of a layer other than its own layer. Its stated here
. You will need to assign some other object as its delegate.
Upvotes: 5