iPad:QuartzCore:多种形状
我是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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
实际的 Quartz 操作并不能保证非常快 - 如果您想要一堆单独的形状分别旋转/缩放,那么您最好将每个形状放在单独的视图中,并通过调整变换属性来执行旋转和缩放。 iOS 中的合成器通过缓存所有视图的图像来工作,并且对变换的调整只需调整缓存图像绘制到屏幕上的方式即可。因此,如果放大得太远,像素化就会成为一个问题,但即使不考虑诸如 CATiledLayer 之类的机制来异步和按需提供不同级别的细节(如在 Safari 中,放大显示视图的像素化版本,然后一旦准备好就转换为全分辨率),您可以最初将视图调整为其最大尺寸,然后将其缩小。
在不确切知道您的专业知识水平的情况下,您可能需要声明一个或多个可以绘制您的形状之一的自定义 UIView 子类。然后,您需要实现自己的 -drawRect: 以及其中的 CoreGraphics 调用。
UIView 上的 Transform 属性采用 CGAffineTransform,并且可以在 CoreAnimation 意义上进行动画处理。
如果您的一个自定义 UIView 只是简单地从视图的左上角到右下角绘制一条对角线(可能是一件无用的事情,但出于示例的目的),您可能会:
那么您可以这样做,例如:
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:
Then you could do, for example: