我使用iOS 5上的Core Plot 1.0在xy图表中使用散点图在自定义刻度位置绘制图标。我在iPad 3上遇到了性能问题,允许用户交互并水平滚动图表。我开始考虑使用CPTGraphHostingView的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;
}
感谢任何帮助。
答案 0 :(得分:1)
Core Plot图中的每一层都应该是CPTLayer
或子类。这对布局和绘图有很多影响。
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];