【问题标题】:Core Plot 1.0 Retina images not displayed correctlyCore Plot 1.0 Retina 图像未正确显示
【发布时间】:2012-09-19 12:02:57
【问题描述】:

我的应用程序即将完成,并在核心情节和他们敬业的员工的帮助下添加了一些很棒的东西。我的问题与使用带有视网膜显示器的图像有关。我有一个注释,它是一个语音气泡的图片。当我在模拟器中运行应用程序时,它在常规分辨率下显示正常,但是当我切换到视网膜时,图像被裁剪。请参阅下面的图片。我有一个名为 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);

}

在那段代码之后,我放置了两个注释。如您所见,一个有效,另一个无效。

【问题讨论】:

    标签: ios core-plot retina-display


    【解决方案1】:

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

    CPTImage *fillimage = [CPTImage imageWithCGImage:bubble.CGImage
                                               scale:bubble.scale];
    

    【讨论】:

    • 再一次,你做到了。感谢你的帮助。我希望我能给你一个我获得的用于分发的促销代码。我知道你可能闭着眼睛写这个应用程序,但这将是一种荣幸!再次感谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多