CGContextClip empty path error (Custom UINavigationBar background)
Getting an error ": doClip: empty path." on
CGContextClip(ctx);
when using Ahmet Ardal's code for custom for UINavigationBar custom background.
Ideally I'd like to solve this error - will it stop approval by Apple?
My understanding is it defines the clipping area to draw in. I have made my navbar graphics the right size so in theory they don't need to be clipped.
Therefore commented out the offending line. Everything seems to be great, but concerned it may have repercussions I'm not aware off
Below is the code tweaked so it works if you have a deeper landscape bar, say with a segmented control in it
- (void) drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx
{
if ([self isMemberOfClass:[UINavigationBar class]] == NO) {
return;
}
//NSLog(@"NAV HEIGHT IS %f %f",self.frame.size.height, self.frame.size.width);
UIImage *image = nil;
if (self.frame.size.width > 320) {
if (self.frame.size.height > 32) {
// Deep NavBar
image = [UINavigationBar bgImageLandscapeDeep];
} else {
image = [UINavigationBar bgImageLandscape];
}
} else {
image = [UINavigationBar bgImagePortrait];
}
NSLog(@"CGContextClip produces <Error>: doClip: empty path. Path is %@",ctx);
//CGContextClip(ctx);
CGContextTranslateCT开发者_开发知识库M(ctx, 0, image.size.height);
CGContextScaleCTM(ctx, 1.0, -1.0);
CGContextDrawImage(ctx, CGRectMake(0, 0, self.frame.size.width, self.frame.size.height), image.CGImage);
}
I inherited an app with a drawLayer:inContext:
method which calls CGContextClip(...)
and produces the "<Error>: doClip: empty path." message.
There have not been any problems submitting this to the store; I'm pretty confident that the error is harmless.
According to Apple's docs:
Parameters
c
A graphics context that contains a path. If the context does not have a current path, the function does nothing.
http://developer.apple.com/library/mac/#documentation/GraphicsImaging/Reference/CGContext/Reference/reference.html
If you really want to prevent logging the error, you should probably check the context before calling CGContextClip(...)
:
if (!CGContextIsPathEmpty(c))
{
CGContextClip(c);
}
Commented out the line, error gone, function behaves.
Caveat: my graphics were correctly sized for the rect, may cause issues if you throw any old graphic into the nav bar
精彩评论