使用核心图形的优势 [英] Advantages of using Core Graphics

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

问题描述

我想知道使用 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 游戏
  • 复杂的 2D 游戏
  • 3D 游戏
  • 代码维护和更简洁的代码.
  • 更轻松地与其他 UI 元素集成.

谢谢.

推荐答案

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

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.

如果您只需要绘制一个 2-D 用户界面,您应该尝试的第一件事是使用 Apple 提供的 UIKit 元素来实现它.如果他们没有您需要的功能,请制作自定义 UIView.如果您正在设计 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 做很多令人惊讶的事情,而且性能非常好.这不仅限于 2-D 动画,还可以扩展到一些简单的 3-D 作品.

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 设备屏幕上看到的所有内容的绘制之下,尽管这不会暴露给您.因此,它为屏幕渲染提供了最少的抽象,并且需要您编写最多的代码来完成某件事.但是,在您希望从 2-D 显示中获得最大性能(例如,在动作游戏中)或渲染真正的 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.

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

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