【问题标题】:CGContextClip empty path error (Custom UINavigationBar background)CGContextClip空路径错误(自定义UINavigationBar背景)
【发布时间】:2011-05-12 17:49:35
【问题描述】:

收到错误“:doClip:空路径。”上

CGContextClip(ctx);

当使用 Ahmet Ardal 的代码自定义 UINavigationBar 自定义背景时。

理想情况下,我想解决这个错误 - 它会停止 Apple 的批准吗?

我的理解是它定义了要绘制的剪切区域。我已将导航栏图形设置为正确的大小,因此理论上它们不需要被剪切。

因此注释掉了有问题的行。一切似乎都很棒,但担心它可能会产生我不知道的影响

以下是经过调整的代码,因此如果您有更深的横向栏(例如其中带有分段控件),它就可以工作

- (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);
}

【问题讨论】:

    标签: iphone ios4 background uinavigationbar


    【解决方案1】:

    我继承了一个带有drawLayer:inContext: 方法的应用程序,该方法调用CGContextClip(...) 并产生“:doClip:空路径”。消息。

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

    根据 Apple 的文档:

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

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

    如果你真的想防止记录错误,你应该在调用CGContextClip(...)之前检查上下文:

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

    【讨论】:

      【解决方案2】:

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

      警告:我的图形大小适合矩形,如果您将任何旧图形扔到导航栏中,可能会导致问题

      【讨论】:

        猜你喜欢
        • 2010-10-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多