[英]How to draw an animatable ruler with Quartz2D?
我想用Quartz2D绘制一个简单的标尺,仅供参考。
由于我不知道要在iPhone上以编程方式进行矢量图形处理,因此也许有人可以为我提供入门的良好教程?
正如Plamen指出的那样, Quartz 2D文档值得一读。 另外,我的iPhone开发课程可以在线获得课程笔记(VoodooPad格式),在那里我将整个课程用于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。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.