【问题标题】:Core Plot Not Displaying Axis Labels With Images When collapsesLayers is YES当collapsesLayers为YES时,核心图不显示带有图像的轴标签
【发布时间】:2012-08-27 18:19:30
【问题描述】:

我在 iOS 5 上使用 Core Plot 1.0 在带有散点图的 xy 图表中的自定义刻度位置绘制图标。我在 iPad 3 上遇到了性能问题,允许用户交互和水平滚动图表。我开始研究使用 CPTGraphHostingView 的 collapsesLayers 属性作为潜在的解决方案。启用它对我来说效果很好,除了一个我还没有解决的特定问题。我设置为渲染图像的自定义轴标签将不会显示。我想知道是否有人对可能是什么原因有任何想法。据我所知,轴标签仍然正确定位在正确的自定义刻度位置。我的外部代码的唯一区别是将 collapsesLayers 从 NO 交换为 YES。

这是我构建轴标签的方式:

+ (CPTAxisLabel *)buildIconAxisLabelAtLocation:(CGFloat)location withImageNamed:(NSString *)imageName
{
CPTLayer *imageLayer = [[CPTLayer alloc] initWithFrame:CGRectMake(0, 0, 16, 16)];

UIImage *image = [UIImage imageNamed:imageName];

CALayer *imageSubLayer = [[CALayer alloc] init];
imageSubLayer.frame = imageLayer.frame;
imageSubLayer.contents = (id)image.CGImage;

[imageLayer addSublayer:imageSubLayer];

CPTAxisLabel *iconLabel = [[CPTAxisLabel alloc] initWithContentLayer:imageLayer];
iconLabel.offset = 8;
iconLabel.tickLocation = CPTDecimalFromCGFloat(location);
iconLabel.rotation = M_PI;

return iconLabel;
}

感谢任何帮助。

【问题讨论】:

    标签: ios core-plot


    【解决方案1】:
    1. Core Plot 图中的每一层都应该是CPTLayer 或子类。这对布局和绘图有很多影响。

    2. Core Plot 不渲染层 contents。改用带有图像填充的CPTBorderedLayer

    我会尝试这样的事情:

    UIImage *image = [UIImage imageNamed:imageName];
    CPTImage *background = [CPTImage imageWithCGImage:image.CGImage];
    CPTBorderedLayer *imageLayer = [[CPTBorderedLayer alloc] initWithFrame:CGRectMake(0, 0, 16, 16)];
    imageLayer.fill = [CPTFill fillWithImage:background];   
    

    【讨论】:

    • 这确实是问题所在。感谢 Eric 的回复以及与 Core Plot 的合作。我只需要做一个小调整:CPTImage *background = [CPTImage imageWithCGImage:image.CGImage scale:[[UIScreen mainScreen] scale]];
    • @Eric 如何在核心情节的 CPTLayer 上添加图像和文本?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-27
    • 1970-01-01
    • 1970-01-01
    • 2012-03-07
    相关资源
    最近更新 更多