2

我的应用程序即将完成,并在核心情节和他们敬业的员工的帮助下添加了一些很棒的东西。我的问题与使用带有视网膜显示器的图像有关。我有一个注释,它是一个语音气泡的图片。当我在模拟器中运行应用程序时,它在常规分辨率下显示正常,但是当我切换到视网膜时,图像被裁剪。请参阅下面的图片。我有一个名为 Bubble 的 .png,我添加了另一个名为 Bubble@2x 的文件,它的大小是原来的两倍,我认为这是我需要做的。那没有用。所以我尝试设置view.contentScale,见下面的代码。但似乎没有任何效果。有人知道我忘记做什么了吗?再次感谢。

{
    //first annotation
    NSValue *value = [self.myData objectAtIndex:index];
    CGPoint point = [value CGPointValue];
    NSString *number1 = [NSString stringWithFormat:@"(%.2f, ", point.x];
    NSString *number2 = [NSString stringWithFormat:@"%.2f)", point.y];
    NSNumber *x = [NSNumber numberWithFloat:point.x];
    NSNumber *y = [NSNumber numberWithFloat:point.y];    
    NSArray *anchorPoint = [NSArray arrayWithObjects: x, y, nil];
    NSString *final = [number1 stringByAppendingString:number2];

    //second annotation        
    UIImage *bubble = [UIImage imageNamed:@"Bubble.png"];
    CPTImage *fillimage = [CPTImage imageWithCGImage:bubble.CGImage];
    CPTBorderedLayer *imageLayer = [[CPTBorderedLayer alloc] init];
    //imageLayer.contentsScale = [[UIScreen mainScreen] scale]; //tried this
    imageLayer.frame = CGRectMake(0, 0, 150, 80);
    //imageLayer.contentsScale = 2.0f;  //and this

    imageLayer.fill = [CPTFill fillWithImage:fillimage];

    CPTTextLayer *textLayer = [[CPTTextLayer alloc] initWithText:final style:annotationTextStyle];
    _annotation = [[CPTPlotSpaceAnnotation alloc] initWithPlotSpace:graph.defaultPlotSpace anchorPlotPoint:anchorPoint];        
    _annotation.contentLayer = textLayer;        
    _annotation.displacement = CGPointMake(90.0f, 5.0f);
    _annotation.rotation = M_PI * .03f;

    _picAnnotation = [[CPTPlotSpaceAnnotation alloc] initWithPlotSpace:graph.defaultPlotSpace anchorPlotPoint:anchorPoint];
    _picAnnotation.contentLayer = imageLayer;
    _picAnnotation.displacement = CGPointMake(75.0f, 5.0f);

}

在该代码之后,我放置了两个注释。如您所见,一个有效,另一个无效。Retina显示屏

常规展示

4

1 回答 1

6

如果您需要支持 Retina 图像,则应scale在创建时传递图像。CPTImage

CPTImage *fillimage = [CPTImage imageWithCGImage:bubble.CGImage
                                           scale:bubble.scale];
于 2012-09-19T23:41:09.850 回答