2012-01-06 83 views
0

我試圖添加圖像註釋到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]; 

這是一個已知的問題?我不明白它爲什麼在模擬器中工作,但不在設備上。

+0

爲什麼你有newLabelLayer和newImageLayer? – 2012-01-06 21:27:24

+0

當我提出這個問題時,這是一個錯字。他們都是新的圖像層。 – user1135111 2012-01-07 01:11:36

回答

0

這可能是因爲您還沒有將test.png添加到目標。這在模擬器中可以正常工作,但是在設備上,如果資源未添加到目標,則不會將其複製到生成的ipa文件。

檢查你的目標的構建階段下複製包資源標籤如果您test.png上市,如果不是你可以只將它拖放。

+0

感謝您的回覆。我仔細檢查了一下,圖像就在那裏。在調試中,我還可以看到UIImage對象已正確創建,只是未在設備的屏幕上顯示。 – user1135111 2012-01-06 21:07:17

1

我認爲你可以使用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]; 
0

資產命名爲「test.png」,OSX中的文件系統是不區分大小寫的,iOS是。這會導致它在模擬器而不是設備上工作。