CGContextClip空路径错误(自定义UINavigationBar背景)

发布于 2024-11-06 15:08:30 字数 1265 浏览 5 评论 0原文

收到错误“: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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

柠北森屋 2024-11-13 15:08:30

我继承了一个带有 drawLayer:inContext: 方法的应用程序,该方法调用 CGContextClip(...) 并生成“: doClip:empty path”。信息。

将其提交给商店没有任何问题;我非常有信心这个错误是无害的。

根据苹果的文档:

参数
c
包含路径的图形上下文。如果上下文没有当前路径,则该函数不执行任何操作。

http://developer.apple.com/ library/mac/#documentation/GraphicsImaging/Reference/CGContext/Reference/reference.html

如果您确实想防止记录错误,您应该在调用 CGContextClip(...)< 之前检查上下文/代码>:

if (!CGContextIsPathEmpty(c))
{
    CGContextClip(c);
}

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);
}
狼亦尘 2024-11-13 15:08:30

注释掉该行,错误消失,函数正常运行。

警告:我的图形尺寸适合矩形,如果您将任何旧图形放入导航栏中,可能会导致问题

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文