gpt4 book ai didi

iphone - 尽管设置了 contentsScale,为什么 CAShapeLayer 还是太大了?

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:49:56 24 4
gpt4 key购买 nike

我有一个 CAShapeLayer,我用它在条形图中绘制小点。问题是它们在视网膜显示器上都太大了。我已设置 contentsScale 并检查它是否已设置。我仍然看不出有没有它有什么区别!

CAShapeLayer *lineShapeLayer = [CAShapeLayer layer];
lineShapeLayer.contentsScale = [[UIScreen mainScreen] scale];
CGMutablePathRef path = CGPathCreateMutable();
lineShapeLayer.backgroundColor = [UIColor clearColor].CGColor;
lineShapeLayer.bounds = CGRectMake(0, 0, self.backgroundLayer.bounds.size.width, 1.5);

lineShapeLayer.anchorPoint = CGPointMake(0, 0);
lineShapeLayer.position = CGPointMake(0, rint((self.verticalPartitionHeight)*i));
lineShapeLayer.lineDashPattern = [NSArray arrayWithObjects:[NSNumber numberWithFloat:1], [NSNumber numberWithInt:2], nil];
lineShapeLayer.strokeColor = [UIColor blackColor].CGColor;
lineShapeLayer.lineWidth = 1;
NSLog(@"contentsScale: %f", lineShapeLayer.contentsScale);

CGPathMoveToPoint(path, nil, 0, .5);
CGPathAddLineToPoint(path, nil, lineShapeLayer.frame.size.width, .5);
[lineShapeLayer setPath:path];

[self.backgroundLayer addSublayer:lineShapeLayer];

这是我使用 PNG 制作的 View : PNGs showing 1px dots

这是带有 CAShapeLayer 代码的 View (设置为线宽 .5 偶数。): CAShapeLayer showing 4px dots :(

最佳答案

您的代码没有任何问题除非它在其他地方。我使用 self.verticalPartitionHeight = 30.0 在循环中运行上面的代码(我假设 i 是索引)。

下面的两张图片是正常分辨率和视网膜分辨率的结果。我已经按比例放大了普通图像,使它们大小相同。如您所见,这些点在两种分辨率下的大小相同(以点为单位,而不是像素)。

Normal resolution, scaled up two times

Retina resolution

编辑:

您提到 Stocks 应用程序在 Landscape 中执行此操作,但如果您放大它的屏幕截图,您实际上会看到它实际上使用了点(因为每个点都是 2x2 像素)。您可以在下面的屏幕截图(来自视网膜屏幕截图)中看到这一点,我在其中放大了很多点并选择了一个点的一个像素。

这是预期的行为。

Stocks.app dots

编辑 2:

再放大看看你的点。它们实际上与 Apples Stocks 应用程序中的点大小完全相同。您可以在下图中看到它,我选择了 一个 像素。

enter image description here

关于iphone - 尽管设置了 contentsScale,为什么 CAShapeLayer 还是太大了?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10760264/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com