使用Core Graphics的优点 [英] Advantages of using Core Graphics

查看:90
本文介绍了使用Core Graphics的优点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道使用Core Graphics而不是Open GL ES可以获得哪些优势。我的主要问题是基于:

I would like to know what kind of advantages I get from using Core Graphics instead of Open GL ES. My main question is based on this:


  • 创建简单的查看动画。

  • 创建一些视觉吸引力对象(例如Core Plot等图形,动画对象等)。

  • 耗时(学习和实现)

  • 简单的2D游戏
  • li>
  • 复杂2D游戏

  • 3D游戏

  • 代码维护广告也更清晰。

  • 更容易与其他UI元素集成。

  • Creating simple View animations.
  • Creating some visual appealing objects (Graphics like Core Plot for instance, Animated Objects, etc).
  • Time consuming (both learning and implementing)
  • Simple 2D Games
  • Complex 2D Games
  • 3D Games
  • Code maintenance ad also cleaner code.
  • Easier integration with other UI elements.

谢谢。

推荐答案

首先,我想在这里澄清一些术语。当人们谈论Core Graphics时,他们通常指的是Quartz 2D绘图,这是一个基于2-D矢量的绘图API。它用于将矢量元素绘制到屏幕或屏幕上下文(如PDF)。核心动画负责动画,布局和一些涉及矩形图层和UI元素的有限三维效果。 OpenGL ES是一个较低级别的API,用于与iOS设备上的图形硬件进行通信,用于2D和3D绘图。

First, I want to clear up a little terminology here. When people talk about Core Graphics, they generally are referring to Quartz 2D drawing, which is a 2-D vector-based drawing API. It is used to draw out vector elements either to the screen or to offscreen contexts like PDFs. Core Animation is responsible for animation, layout, and some limited 3-D effects involving rectangular layers and UI elements. OpenGL ES is a lower-level API for talking with the graphics hardware on iOS devices for both 2-D and 3-D drawing.

你在询问很多你的问题,以及对每种情况下最佳情况的判断是主观的,完全取决于开发者及其特殊需求。但是,我可以提供一些一般性提示。

You're asking a lot in your question, and the judgment on what's best in each scenario is subjective and completely up to the developer and their particular needs. I can, however, provide a few general tips.

一般来说,您在Apple的文档和工程师的演示文稿中看到的建议是您最好的使用最高级别的抽象来解决您的特定问题。

In general, a recommendation you'll see in Apple's documentation and in presentations by engineers is that you're best off using the highest level of abstraction that solves your particular problem.

如果您只需绘制一个二维用户界面,首先应该尝试使用Apple提供的UIKit元素实现这一点。如果他们没有您需要的功能,请制作自定义UIViews。如果您正在设计Mac-iOS跨平台代码(如Core Plot框架中),您可能会使用自定义Core Animation CALayers。在此过程中的每一步都需要您编写更多代码来处理上述级别为您所做的事情。

If you need to just draw a 2-D user interface, the first thing you should try is to implement this using Apple's provided UIKit elements. If they don't have the capability you need, make custom UIViews. If you are designing Mac-iOS cross-platform code (like in the Core Plot framework), you might drop down to using custom Core Animation CALayers. Each step down in this process requires you to write more code to handle things that the level above did for you.

您可以使用Core Animation做一些惊人的事情,表现相当不错。这不仅限于二维动画,还可以扩展到一些简单的三维工作。

You can do a surprising amount of stuff with Core Animation, with pretty good performance. This isn't just limited to 2-D animations, but can extend into some simple 3-D work as well.

OpenGL ES位于您看到的所有内容的下方在iOS设备的屏幕上,虽然这不是暴露给你。因此,它为屏幕渲染提供了最少的抽象,并且需要您编写最多的代码来完成某些操作。但是,在您希望从2D显示中提取最佳性能(例如,在动作游戏中)或渲染真实的3-D对象和环境时,可能需要它。

OpenGL ES is underneath the drawing of everything you see on the screen for an iOS device, although this is not exposed to you. As such, it provides the least abstraction for onscreen rendering, and requires you to write the most code to get something done. However, it can be necessary in situations where you want to extract the most performance from 2-D display (say, in an action game) or to render true 3-D objects and environments.

同样,我倾向于建议人们在编写应用程序时从最高抽象级别开始,只有当他们发现他们无法做某事或性能不符合他们试图达到的规范时才会下降。更少的代码行使应用程序更容易编写,调试和维护。

Again, I tend to recommend that people start at the highest level of abstraction when writing an application, and only drop down when they find that they cannot do something or the performance is not within the specification they are trying to hit. Fewer lines of code makes applications easier to write, debug, and maintain.

也就是说,有一些很好的框架围绕抽象OpenGL ES开发,例如cocos2D和Unity 3D,在许多情况下可能更容易使用OpenGL ES。对于每种情况,您都需要评估对您的应用程序的特定需求有意义的内容。

That said, there are some nice frameworks that have developed around abstracting away OpenGL ES, such as cocos2D and Unity 3D, which might make working with OpenGL ES easier in many situations. For each case, you'll need to evaluate what makes sense for the particular needs of your application.

这篇关于使用Core Graphics的优点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆