CPTPlotSpaceAnnotation与图像不工作在设备上,在模拟器中工作
我试图添加图像注释到barplot。它在iOS模拟器中工作正常,但图像注释未在设备上显示。我正在使用Xcode 4.2。在两个设备上测试,一个是iOS 4.3,另一个是iOS5.0.1。CPTPlotSpaceAnnotation与图像不工作在设备上,在模拟器中工作
我正在使用armv7和Apple LLVM 3.0编译器。我知道图像文件名称区分大小写,并且是正确的。
的一段代码我试过低于:
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];
这是一个已知的问题?我不明白它为什么在模拟器中工作,但不在设备上。
这可能是因为您还没有将test.png
添加到目标。这在模拟器中可以正常工作,但是在设备上,如果资源未添加到目标,则不会将其复制到生成的ipa文件。
检查你的目标的构建阶段下复制包资源标签如果您test.png
上市,如果不是你可以只将它拖放。
感谢您的回复。我仔细检查了一下,图像就在那里。在调试中,我还可以看到UIImage对象已正确创建,只是未在设备的屏幕上显示。 – user1135111 2012-01-06 21:07:17
我认为你可以使用CPTForderedLayer上的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];
资产命名为“test.png”,OSX中的文件系统是不区分大小写的,iOS是。这会导致它在模拟器而不是设备上工作。
为什么你有newLabelLayer和newImageLayer? – 2012-01-06 21:27:24
当我提出这个问题时,这是一个错字。他们都是新的图像层。 – user1135111 2012-01-07 01:11:36