iPad:QuartzCore:多种形状

发布于 2024-10-09 02:34:46 字数 98 浏览 0 评论 0原文

我是quartzCore 的新手,不太容易习惯它。 我想在视图中绘制一些基本形状并独立旋转/放大它们中的每一个。

您能给我一些关于如何做到这一点的指导或想法吗? 谢谢

I'm new to quartzCore and i'm not getting used to it so easily.
I want to draw some basic shapes in a view and rotate/magnify each one of them independently.

Can you give me some directions or ideas on how to do that ?
thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夏有森光若流苏 2024-10-16 02:34:46

实际的 Quartz 操作并不能保证非常快 - 如果您想要一堆单独的形状分别旋转/缩放,那么您最好将每个形状放在单独的视图中,并通过调整变换属性来执行旋转和缩放。 iOS 中的合成器通过缓存所有视图的图像来工作,并且对变换的调整只需调整缓存图像绘制到屏幕上的方式即可。因此,如果放大得太远,像素化就会成为一个问题,但即使不考虑诸如 CATiledLayer 之类的机制来异步和按需提供不同级别的细节(如在 Safari 中,放大显示视图的像素化版本,然后一旦准备好就转换为全分辨率),您可以最初将视图调整为其最大尺寸,然后将其缩小。

在不确切知道您的专业知识水平的情况下,您可能需要声明一个或多个可以绘制您的形状之一的自定义 UIView 子类。然后,您需要实现自己的 -drawRect: 以及其中的 CoreGraphics 调用。

UIView 上的 Transform 属性采用 CGAffineTransform,并且可以在 CoreAnimation 意义上进行动画处理。

如果您的一个自定义 UIView 只是简单地从视图的左上角到右下角绘制一条对角线(可能是一件无用的事情,但出于示例的目的),您可能会:

- (void)drawRect:(CGRect)rect
{
    CGContextRef context = UIGraphicsGetCurrentContext();

    CGContextSaveGState(context);

    // we're relative to the inside of the view, so...
    CGPoint points[2]; 
    points[0] = CGPointMake(0, 0); 
    points[1] = CGPointMake(self.bounds.size.width, self.bounds.size.height);

    CGContextSetGrayStrokeColor(context, 0.6, 0.6);
    CGContextSetLineWidth(context, 2.0);
    CGContextStrokeLineSegments(context, points, 2);

    CGContextRestoreGState(context);
}

那么您可以这样做,例如:

view.transform = CGAffineTransformMakeScale(0.5, 0.5);

Actual Quartz operations aren't guaranteed to be very speedy — if you want a bunch of separate shapes which rotate/scale separately then you're better off putting each in a separate view and performing the rotation and scaling by adjusting the transform property. The compositor in iOS works by caching the image of all views and adjustments to the transform simply adjust how the cached image is drawn to the screen. Hence pixellation would be an issue if you zoomed in too far, but even without going into the mechanisms such as CATiledLayer for providing different levels of detail asynchronously and on demand (as in Safari, where zooming in shows the pixellated version of the view and then transitions to a full resolution one as soon as it is ready), you could just size the views at their maximum size initially and then scale them down.

Without knowing exactly your level of expertise, you'll want to declare one or more custom UIView subclasses that can draw one of your shapes. You'll then want to implement your own -drawRect: with the CoreGraphics calls within it.

The transform property on a UIView takes a CGAffineTransform and can be animated in the CoreAnimation sense.

If one of your custom UIViews were simply to draw a diagonal line from the top left of the view to the bottom right (a useless thing to do, probably, but for the purposes of example), you might have:

- (void)drawRect:(CGRect)rect
{
    CGContextRef context = UIGraphicsGetCurrentContext();

    CGContextSaveGState(context);

    // we're relative to the inside of the view, so...
    CGPoint points[2]; 
    points[0] = CGPointMake(0, 0); 
    points[1] = CGPointMake(self.bounds.size.width, self.bounds.size.height);

    CGContextSetGrayStrokeColor(context, 0.6, 0.6);
    CGContextSetLineWidth(context, 2.0);
    CGContextStrokeLineSegments(context, points, 2);

    CGContextRestoreGState(context);
}

Then you could do, for example:

view.transform = CGAffineTransformMakeScale(0.5, 0.5);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文