gpt4 book ai didi

iphone - 如何使用 Quartz2D 绘制可动画的标尺?

转载 作者:行者123 更新时间:2023-12-03 20:49:15 26 4
gpt4 key购买 nike

我想用 Quartz2D 画一把简单的尺子的线条,仅供练习。

由于我不知道如何在 iPhone 上以编程方式制作矢量图形,也许有人可以给我指点一个好的入门教程?

最佳答案

正如 Plamen 指出的那样,Quartz 2D documentation值得一读。此外,类(class)笔记are available online (VoodooPad 格式)用于我的 iPhone 开发类(class),我将整个类(class)用于 Quartz 2D 绘图。 QuartzExamples我创建的示例应用程序显示了一些更高级的绘图概念,但是 Apple 的 QuartzDemo示例是了解如何进行简单绘图的更好起点。

作为为标尺绘制刻度的示例,以下是我用来执行类似操作的代码:

NSInteger minorTickCounter = majorTickInterval;
NSInteger totalNumberOfTicks = totalTravelRangeInMicrons / minorTickSpacingInMicrons;
CGFloat minorTickSpacingInPixels = currentHeight / (CGFloat)totalNumberOfTicks;

CGContextSetStrokeColorWithColor(context, [MyView blackColor]);

for (NSInteger currentTickNumber = 0; currentTickNumber < totalNumberOfTicks; currentTickNumber++)
{
CGContextMoveToPoint(context, leftEdgeForTicks + 0.5, round(currentTickNumber * minorTickSpacingInPixels) + 0.5);

minorTickCounter++;
if (minorTickCounter >= majorTickInterval)
{
CGContextAddLineToPoint(context, round(leftEdgeForTicks + majorTickLength) + 0.5, round(currentTickNumber * minorTickSpacingInPixels) + 0.5);
minorTickCounter = 0;
}
else
{
CGContextAddLineToPoint(context, round(leftEdgeForTicks + minorTickLength) + 0.5, round(currentTickNumber * minorTickSpacingInPixels) + 0.5);
}
}

CGContextStrokePath(context);

其中 currentHeight 是要覆盖的区域的高度,[MyView blackColor] 仅返回表示黑色的 CGColorRef。

关于iphone - 如何使用 Quartz2D 绘制可动画的标尺?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2532805/

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