【问题标题】:CPTPlotSpaceAnnotation with image not working on Device, works in simulator带有图像的 CPTPlotSpaceAnnotation 无法在设备上运行,可在模拟器中运行
【发布时间】:2012-01-06 20:45:22
【问题描述】:

我尝试向条形图添加图像注释。它在 iOS 模拟器中运行良好,但设备上未显示图像注释。我正在使用 Xcode 4.2。在两台设备上测试,一台是iOS 4.3,另一台是iOS5.0.1。

我正在使用带有 Apple LLVM 3.0 编译器的 armv7。我知道图像文件名区分大小写并且是正确的。

我试过的代码如下:

CPTPlotSpaceAnnotation *imageAnnotation;
CGRect imageRect = CGRectMake(50, 50 ,30, 30);
CPTLayer *newImagelLayer = [[CPTLayer alloc] initWithFrame:imageRect];
newImagelLayer.contents = (id)[[UIImage imageNamed:@"test.png"] CGImage];
imageAnnotation = [[CPTPlotSpaceAnnotation alloc] initWithPlotSpace:plotSpace anchorPlotPoint:nil];
imageAnnotation.contentLayer = newImagelLayer;
[barPlot addAnnotation:imageAnnotation];
[newImagelLayer release];
[imageAnnotation release];

这是一个已知问题吗?我不明白为什么它在模拟器上有效,但在设备上无效。

【问题讨论】:

  • 为什么会有newLabelLayer和newImageLayer?
  • 当我提出问题时,这是一个错字。它们都是newImagelLayer。

标签: iphone


【解决方案1】:

我认为您可以通过在 CPTBorderedLayer 上使用 CPTFill 来做到这一点。

CPTPlotSpaceAnnotation *imageAnnotation;
CGRect imageRect = CGRectMake(50, 50 ,30, 30);
CPTBorderedLayer *newImagelLayer = [[CPTBorderedLayer alloc] initWithFrame:imageRect];
newImagelLayer.fill = [CPTFill fillWithImage:[CPTImage imageWithCGImage:[[UIImage imageNamed:@"dot-selector.png"] CGImage]]];
imageAnnotation = [[CPTPlotSpaceAnnotation alloc] initWithPlotSpace:plotSpace anchorPlotPoint:nil];
imageAnnotation.contentLayer = newImagelLayer;
[barPlot addAnnotation:imageAnnotation];
[newImagelLayer release];
[imageAnnotation release];

【讨论】:

    【解决方案2】:

    这可能是因为您没有将test.png 添加到目标中。这在模拟器中可以正常工作,但在设备上,如果资源没有添加到目标,它不会被复制到生成的 ipa 文件中。

    如果您的 test.png 已列出,请在 Copy Bundle Resources 下检查目标的 Build Phases 选项卡,否则您可以直接拖放它。

    【讨论】:

    • 感谢您的回复。我做了仔细检查,图像在那里。在调试中,我还可以看到 UIImage 对象被正确创建,只是没有显示在设备的屏幕上。
    【解决方案3】:

    OSX 中的文件系统是否完全命名为“test.png”,iOS 是不区分大小写的。这将导致它适用于模拟器而不适用于设备。

    【讨论】:

      猜你喜欢
      • 2011-03-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-27
      • 1970-01-01
      • 2014-12-24
      • 2023-03-24
      • 2016-02-02
      相关资源
      最近更新 更多