iOS文档--Drawing and Printing Guide for iOS(介绍章节)

 

About Drawing and Printing in iOS          --关于iOS中的绘图和打印

This document covers three related subjects:

--该文档覆盖了三个主题:

  • Drawing custom UI views. Custom UI views allow you to draw content that cannot easily be drawn with standard UI elements. For example, a drawing program might use a custom view for the user’s drawing, or an arcade game might use a custom view into which it draws sprites.
         --绘制自定义用户界面视图。自定义UI视图允许您绘制 “不能用标准UI元素就轻松绘制的” 内容。例如,绘图程序可能使用“自定义的视图”来绘制用户的绘图,也可能是街机游戏使用”自定义视图“来绘制小精灵。

  • Drawing into offscreen bitmap and PDF content. Whether you plan to display the images later, export them to a file, or print the images to an AirPrint-enabled printer, offscreen drawing lets you do so without interrupting the user’s workflow.
          --绘制视图到屏幕外的“位图和PDF的”内容中。无论您计划以后再显示图像,还是将其导出到文件中,还是将图像打印到AirPrint的打印机中,屏幕外的绘图技术都支持这样的操作,而不会中断用户的工作流程。

  • Adding AirPrint support to your app. The iOS printing system lets you draw your content differently to fit on the page.
           --添加“无线打印的支持”到我们的app中。iOS打印系统允许您以不同的方式绘制内容以适合页面。

Figure I-1  You can combine custom views with standard views, and even draw things offscreen.

                 --您可以将自定义视图与标准视图结合起来,甚至可以在屏幕外绘制内容。

 

 

At a Glance            --简介

The iOS native graphics system combines three major technologies: UIKit, Core Graphics, and Core Animation. UIKit provides views and some high-level drawing functionality within those views, Core Graphics provides additional (lower-level) drawing support within UIKit views, and Core Animation provides the ability to apply transformations and animation to UIKit views. Core Animation is also responsible for view compositing.

         --iOS原生图形系统结合了三种主要技术:UIKit、Core Graphics, Core AnimationUIKit提供了view和view中的一些高级绘图功能,Core Graphics在UIKit的view基础上提供了附加(低级)的绘图支持,Core Animation提供了在UIKit的view进行转换和动画能力。Core Animation还负责view合成。

 

Custom UI Views Allow Greater Drawing Flexibility      --自定义UI视图允许更复杂的绘图

This document describes how to draw into custom UI views using native drawing technologies. These technologies, which include the Core Graphics and UIKit frameworks, support 2D drawing.

       --本文描述了如何使用“本地绘图技术”来绘制自定义视图。这些技术支持2D绘图,包括了Core GraphicsUIKit框架

Before you consider using a custom UI view, you should make certain that you really need to do so. Native drawing is suitable for handling more complex 2D layout needs. However, because custom views are processor-intensive, you should limit the amount of drawing you do using native drawing technologies.

      --在考虑使用自定义UI视图之前,应该确保是否真的需要这样做。本地绘图适合处理更复杂的二维布局需求。但是,由于自定义视图是处理器密集型视图,因此你应节制地使用“本地绘图技术”进行大量绘图。

As an alternative to custom drawing, an iOS app can draw things onscreen in several other ways.

          --除了自定义绘图之外,iOS app也可以用以下几种方式在屏幕上绘制内容:

  • Using standard (built-in) views. Standard views let you draw common user-interface primitives, including lists, collections, alerts, images, progress bars, tables, and so on without the need to explicitly draw anything yourself. Using built-in views not only ensures a consistent user experience between iOS apps, but also saves you programming effort. If built-in views meet your needs, you should read View Programming Guide for iOS.
          --使用标准(内置)视图。标准视图允许您绘制常见的用户界面原语,例如 lists, collections, alerts, images, progress bars, tables等等,而无需自己显式绘制任何内容。使用内置视图不仅可以确保iOS app之间的一致用户体验,还可以节省编程工作量。如果内置视图满足您的需要,您应该阅读View Programming Guide for iOS

  • Using Core Animation layers. Core Animation lets you create complex, layered 2D views with animation and transformations. Core Animation is a good choice for animating standard views, or for combining views in complex ways to present the illusion of depth, and can be combined with custom-drawn views as described in this document. To learn more about Core Animation, read Core Animation Overview.
              --使用核心动画中的layers。Core Animation 允许您使用“动画和变换”来创建“复杂的分层”二维视图。核心动画是制作“标准视图动画”或以复杂方式组合视图以“呈现深度幻觉”的好选择,还可以与本文档中描述的自定义绘制视图组合。要了解有关核心动画的更多信息,请阅读Core Animation Overview

  • Using OpenGL ES in a GLKit view or a custom view. The OpenGL ES framework provides a set of open-standard graphics libraries geared primarily toward game development or apps that require high frame rates, such as virtual prototyping apps and mechanical and architectural design apps. It conforms to the OpenGL ES 2.0 and OpenGL ES v1.1 specifications. To learn more about OpenGL drawing, read OpenGL ES Programming Guide.
               --在GLKit View或自定义View中使用OpenGL ES。OpenGL ES框架 提供了一组开放的 标准图形库,主要面向游戏开发或需要高帧速率的应用程序,如虚拟原型应用程序、机械和架构设计应用程序。它符合OpenGL ES 2.0和OpenGL ES v1.1规范。要了解有关OpenGL绘图的更多信息,请阅读OpenGL ES Programming Guide.。

  • Using web content. The UIWebView class lets you display web-based user interfaces in an iOS app. To learn more about displaying web content in a web view, read Using UIWebView to display select document types and UIWebView Class Reference.
              --使用web内容UIWebView类允许您在iOS app中显示基于web的用户界面。若要了解有关在web视图中显示web内容的详细信息,请阅读Using UIWebView to display select document typesUIWebView Class Reference

Depending on the type of app you are creating, it may be possible to use little or no custom drawing code. Although immersive apps typically make extensive use of custom drawing code, utility and productivity apps can often use standard views and controls to display their content.

         --根据您正在创建的app的类型,可能很少使用或根本就没有自定义的绘图代码。尽管沉浸式app通常广泛地使用自定义绘图代码,但实用app和生产效率app通常使用标准视图和控件就足以显示其内容。

The use of custom drawing code should be limited to situations where the content you display needs to change dynamically. For example, a drawing app typically needs to use custom drawing code to track the user’s drawing commands, and an arcade-style game may need to update the screen constantly to reflect the changing game environment. In those situations, you should choose an appropriate drawing technology and create a custom view class to handle events and update the display appropriately.

     --自定义绘图代码的使用 应限于 ”显示的内容“需要动态更改的情况。例如,绘图app通常需要使用“自定义绘图代码”来跟踪用户的绘图命令,而”街机风格的游戏app“则可能需要不断更新屏幕以反映不断变化的游戏环境。在这些情况下,应选择适当的绘图技术并创建自定义view类以处理事件并适当更新显示。

On the other hand, if the bulk of your app’s interface is fixed, you can render the interface in advance to one or more image files and display those images at runtime using the UIImageView class. You can layer image views with other content as needed to build your interface. You can also use the UILabel class to display configurable text and include buttons or other controls to provide interactivity. For example, an electronic version of a board game can often be created with little or no custom drawing code.

           --另一方面,如果app的大部分接口都是固定的,则可以提前将该接口呈现给一个或多个图像文件,并在运行时使用 UIImageView 类来显示这些图像。可以根据需要 将“UIImageView”与“其他内容”分层 以构建界面。您还可以使用UILabel类来显示可配置的文本,并引入按钮或其他控件来提供交互性。例如,电子版的棋盘游戏通常可以创建很少或没有自定义的绘图代码。

Because custom views are generally more processor-intensive (with less help from the GPU), if you can do what you need to do using standard views, you should always do so. Also, you should make your custom views as small as possible, containing only content that you cannot draw in any other way, use use standard views for everything else. If you need to combine standard UI elements with custom drawing, consider using a Core Animation layer to superimpose a custom view with a standard view so that you draw as little as possible.

          --由于自定义视图通常需要更多的处理器(GPU的帮助较少),你最好尽可能地使用标准视图来完成所需的工作。此外,您应该使您的自定义视图尽可能小,最好只包含“不能以任何其他方式绘制的”内容,而其他内容则使用标准视图。如果需要将标准UI元素与自定义绘图结合起来,请考虑使用Core Animation layer 将自定义视图与标准视图叠加,以便尽可能少地绘制。

 

A Few Key Concepts Underpin Drawing With the Native Technologies

         --使用本地绘图技术的几个关键概念

When you draw content with UIKit and Core Graphics, you should be familiar with a few concepts in addition to the view drawing cycle.

         --使用UIKit和Core Graphics绘制内容时,除了视图绘制周期外,还应熟悉以下的一些概念:

  • For the drawRect: method, UIKit creates a graphics context for rendering to the display. This graphics context contains the information the drawing system needs to perform drawing commands, including attributes such as fill and stroke color, the font, the clipping area, and line width. You can also create and draw into custom graphics context for bitmap images and PDF content.
          --对于 drawRect: 方法,UIKit创建graphics context以渲染显示。此图形上下文包含绘图系统“执行绘图命令所需的”信息,包括诸如填充、笔划颜色、字体、剪裁区域和线宽等属性。您还可以使用graphics context创建“位图图像”和“PDF内容”到自定义图像中。

  • UIKit has a default coordinate system where the origin of drawing is at the top-left of a view; positive values extend downward and to the right of that origin. You can change the size, orientation, and position of the default coordinate system relative to the underlying view or window by modifying the current transformation matrix, which maps a view’s coordinate space to the device screen.
              --UIKit有一个默认坐标系,其中图形的原点在视图的左上角;正值向下延伸到原点的右侧。你可以通过修改当前变换矩阵(将视图的坐标空间映射到设备屏幕),从而更改“默认坐标系”相对于基础view或window的大小、方向和位置。

  • In iOS, the logical coordinate space, which measures distances in points, is not equal to the device coordinate space, which measures in pixels. For greater precision, points are expressed in floating-point values.
               --在iOS中,逻辑坐标空间(以点为单位度量距离)并不等于设备坐标空间(以像素为单位度量距离)。为了获得更高的精度,点用浮点值表示。

Relevant Chapter: iOS Drawing Concepts           --有关本地绘图技术概念的下一章节

 

UIKit, Core Graphics, and Core Animation Give Your App Many Tools For Drawing

        --UIKit, Core Graphics,和Core Animation可以给你的app提供很多绘图工具

The UIKit and Core Graphics have many complementary graphics capabilities that encompass graphics contexts, Bézier paths, images, bitmaps, transparency layers, colors, fonts, PDF content, and drawing rectangles and clipping areas. In addition, Core Graphics has functions related to line attributes, color spaces, pattern colors, gradients, shadings, and image masks. The Core Animation framework enables you to create fluid animations by manipulating and displaying content created with other technologies.

        --UIKitCore Graphics具有许多互补的图形功能,包括图形上下文、贝塞尔曲线路径、图像、位图、透明度图层、颜色、字体、PDF内容以及绘制矩形和剪贴区。 此外,Core Graphics还具有与线条属性、色彩空间、图案颜色、渐变、阴影和图像蒙版相关的功能。 Core Animation框架可以让您为”其他技术创建的内容“来创建流畅的动画

Relevant Chapters: iOS Drawing Concepts, Drawing Shapes Using Bézier Paths, Drawing and Creating Images, Generating PDF Content                             --相关绘图技术参考章节

 

Apps Can Draw Into Offscreen Bitmaps or PDFs             --app可以绘制图像到屏幕外的位图或PDF中

It is often useful for an app to draw content offscreen:

     --app在屏幕外绘制内容是很常用的:

  • Offscreen bitmap contexts are often used when scaling down photographs for upload, rendering content into an image file for storage purposes, or using Core Graphics to generate complex images for display.
       --屏幕外的“位图上下文”通常用于缩小照片以供上载、将内容呈现到图像文件以供存储或使用Core Graphics生成复杂图像以供显示。

  • Offscreen PDF contexts are often used when drawing user-generated content for printing purposes.
         --出于打印“目的”绘制用户生成的内容时,通常使用屏幕外的“PDF上下文”

After you create an offscreen context, you can draw into it just as you would draw within the drawRect: method of a custom view.

           --在你创建“屏幕外的上下文”后,你可以像在自定义视图的drawRect:方法中绘制一样绘制到上下文中。

Relevant Chapters: Drawing and Creating Images, Generating PDF Content           --参考章节:创建与绘制图片,生成pdf内容

 

Apps Have a Range of Options for Printing Content              --app有一系列打印内容的选项

As of iOS 4.2, apps can print content wirelessly to supported printers using AirPrint. When assembling a print job, they have three ways to give UIKit the content to print:

    --从iOS 4.2开始,应用程序可以使用AirPrint将内容无线打印到支持的打印机。在组装打印作业时,他们有三种方法为UIKit提供要打印的内容:

  • They can give the framework one or more objects that are directly printable; such objects require minimal app involvement. These are instances of the NSData, NSURL, UIImage, or ALAsset classes containing or referencing image data or PDF content.
       --它们可以为框架提供一个或多个可直接打印的对象;这些对象只需要最少的应用程序参与。这些是包含或引用图像数据或PDF内容的NSData、NSURL、UIImage或ALAsset类的实例。

  • They can assign a print formatter to the print job. A print formatter is an object that can lay out content of a certain type (such as plain text or HTML) over multiple pages.
         --他们可以为打印作业分配打印格式化程序。打印格式化程序是一个对象,它可以在多个页面上布局特定类型的内容(如纯文本或HTML)。

  • They can assign a page renderer to the print job. A page renderer is usually an instance of a custom subclass of UIPrintPageRenderer that draws the content to be printed in part or in full. A page renderer can use one or more print formatters to help it draw and format its printable content.
       --他们可以为打印作业分配页面呈现程序。页面呈现器通常是UIPrintPageRenderer的自定义子类的实例,该子类绘制部分或全部要打印的内容。页面呈现程序可以使用一个或多个打印格式化程序来帮助绘制和格式化其可打印内容。

Relevant Chapter: Printing

 

It’s Easy to Update Your App for High-Resolution Screens

Some iOS devices feature high-resolution screens, so your app must be prepared to run on these devices and on devices with lower-resolution screens. iOS handles much of the work required to handle the different resolutions, but your app must do the rest. Your tasks include providing specially named high-resolution images and modifying your layer- and image-related code to take the current scale factor into account.

     --某些iOS设备具有高分辨率屏幕,因此您的app必须准备好在这些设备和具有低分辨率屏幕的设备上运行。iOS处理了处理不同分辨率所需的大部分工作,但你的应用必须完成其余的工作。您的任务包括提供特别命名的高分辨率图像,并修改与图层和图像相关的代码以将当前的比例因子考虑在内。

Relevant Appendix: Supporting High-Resolution Screens In Views

 

See Also

For complete examples of printing, see the PrintPhoto: Using the Printing API with Photos, Sample Print Page Renderer, and UIKit Printing with UIPrintInteractionController and UIViewPrintFormatter sample code projects.

 

第一章

----------------------------------------------------------------------


 

 

 

 

 

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值