CGContextClip空路径错误(自定义UINavigationBar背景)
收到错误“:doClip:空路径。” 启用
CGContextClip(ctx);
当使用 Ahmet Ardal 的代码进行 UINavigationBar 自定义背景的自定义时
。理想情况下,我想解决这个错误 - 它会停止苹果的批准吗?
我的理解是它定义了要绘制的剪切区域。我已经将导航栏图形设置为正确的尺寸,因此理论上它们不需要被剪切。
因此注释掉了有问题的行。一切似乎都很棒,但担心它可能会产生影响,我不知道
下面是经过调整的代码,因此如果您有更深的景观栏(例如其中有分段控件),它就可以工作
- (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);
CGContextTranslateCTM(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);
}
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);
CGContextTranslateCTM(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);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我继承了一个带有: doClip:empty path”。信息。
drawLayer:inContext:
方法的应用程序,该方法调用CGContextClip(...)
并生成“将其提交给商店没有任何问题;我非常有信心这个错误是无害的。
根据苹果的文档:
http://developer.apple.com/ library/mac/#documentation/GraphicsImaging/Reference/CGContext/Reference/reference.html
如果您确实想防止记录错误,您应该在调用 CGContextClip(...)< 之前检查上下文/代码>:
I inherited an app with a
drawLayer:inContext:
method which callsCGContextClip(...)
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:
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(...)
:注释掉该行,错误消失,函数正常运行。
警告:我的图形尺寸适合矩形,如果您将任何旧图形放入导航栏中,可能会导致问题
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