在iPhone上使用Quartz绘制几个转换后的图像

时间:2021-01-15 19:48:16

I'm trying to figure out how best to accomplish drawing a scene in an iphone app. Here is the situation:

我正在试图弄清楚如何最好地在iPhone应用程序中绘制场景。情况如下:

  • I have a single view that I would like to draw to
  • 我有一个我想要绘制的视图

  • I would like to have a background image
  • 我想有一个背景图片

  • I would like to draw several different images on top of the background each which have separate transforms applied to them (rotation, scaling)
  • 我想在背景上绘制几个不同的图像,每个图像都应用了单独的变换(旋转,缩放)

  • I would like to draw several blocks of text on top of the background image as well - I need to word break these as well as transform them (rotation, scaling)
  • 我想在背景图像的顶部绘制几个文本块 - 我需要对它们进行单词分解以及转换它们(旋转,缩放)

  • I would like to animate these images and blocks of text being drawn on screen (I don't need to do this in the first iteration but I don't want to choose a path that will preclude me from doing this in the future.
  • 我想在屏幕上绘制这些图像和文本块的动画(我不需要在第一次迭代中执行此操作,但我不想选择一条将阻止我在将来执行此操作的路径。

I'm not really sure where to start - but because things aren't animated too much it doesn't seem like this has to be really performant so I'm thinking Quartz will be the way to go.

我不确定从哪里开始 - 但是因为事情没有太多动画,所以看起来不一定非常高效,所以我认为Quartz将是最佳选择。

Some possible solutions I can think of:

我能想到的一些可能的解决方案:

  • Use quartz: Draw the background to a view's cgcontext. Create several CGLayers and draw the text/images to them. Transform the CGlayers (can you do this?) then draw the layers to the main CGContext.

    使用quartz:将背景绘制到视图的cgcontext中。创建几个CGLayers并将文本/图像绘制到它们。转换CGlayers(你可以这样做吗?)然后将图层绘制到主CGContext。

  • use OpenGL: please no. unless I really need to.

    使用OpenGL:请不要。除非我真的需要。

Ideas?

Thanks.

2 个解决方案

#1


Mostly agree with Marco. CA is perfect for this work. Set up a view and add a bunch of layers.

大部分同意Marco。 CA非常适合这项工作。设置视图并添加一堆图层。

A couple of points though.

但有几点。

You can directly draw text using the NSString UIStringDrawing category methods. works really well and don't have the overhead of UILabel.

您可以使用NSString UIStringDrawing类别方法直接绘制文本。工作得很好,没有UILabel的开销。

Drawing with CoreGraphics is not too slow, because CoreAnimation intelligently caches the layer. That is, it's only drawn once and then CA animates a copy unless the layer is sent a setNeedsDisplay message.

使用CoreGraphics绘图并不会太慢,因为CoreAnimation会智能地缓存图层。也就是说,它只绘制一次然后CA动画副本,除非该层发送setNeedsDisplay消息。

#2


Use CoreAnimation CALayers for the imags (you can apply tranformations to them) and UILabels for the text. Drawing with CoreGraphics will be too slow for animating.

对于imags(可以对它们应用转换)和文本的UILabel使用CoreAnimation CALayers。使用CoreGraphics绘制对于动画来说太慢了。

#1


Mostly agree with Marco. CA is perfect for this work. Set up a view and add a bunch of layers.

大部分同意Marco。 CA非常适合这项工作。设置视图并添加一堆图层。

A couple of points though.

但有几点。

You can directly draw text using the NSString UIStringDrawing category methods. works really well and don't have the overhead of UILabel.

您可以使用NSString UIStringDrawing类别方法直接绘制文本。工作得很好,没有UILabel的开销。

Drawing with CoreGraphics is not too slow, because CoreAnimation intelligently caches the layer. That is, it's only drawn once and then CA animates a copy unless the layer is sent a setNeedsDisplay message.

使用CoreGraphics绘图并不会太慢,因为CoreAnimation会智能地缓存图层。也就是说,它只绘制一次然后CA动画副本,除非该层发送setNeedsDisplay消息。

#2


Use CoreAnimation CALayers for the imags (you can apply tranformations to them) and UILabels for the text. Drawing with CoreGraphics will be too slow for animating.

对于imags(可以对它们应用转换)和文本的UILabel使用CoreAnimation CALayers。使用CoreGraphics绘制对于动画来说太慢了。