关闭

animation - 2

标签: iosanimationuiview
257人阅读 评论(0) 收藏 举报
分类:

继续了解几个概念才进入真正的animation的学习,因为iOS关于animation的知识体系实在是太大太磅礴了,一定要把基础和基本概念彻底弄清楚弄了解。


Drawing model

Drawing in iOS and OS X follows one of two technology paths and is based on a model in which views update their appearance on demand. To draw your application’s content you can use either OpenGL or the native rendering facilities of the platform.

  • OpenGL. OpenGL is a C-based interface for creating 2D and 3D content on desktop computers. It is ideal for immersive types of applications, such as games, or for applications that require high frame rates. For OS X, there is a desktop version of the OpenGL framework; for iOS, there is the OpenGL ES framework, which is optimized for use on embedded hardware systems.
  • Native support. The Quartz (Core Graphics), Core Animation, and application frameworks for each platform (UIKit and AppKit) provide native graphics support using an object-oriented model. Quartz is the main drawing interface, providing support for path-based drawing, anti-aliased rendering, gradient fill patterns, images, colors, coordinate-space transformations, and PDF document creation, display, and parsing. You can use Core Animation to animate changes in many view properties and to implement custom animations. UIKit and AppKit both include Objective-C classes that represent graphical entities such as images, colors, and bezier paths; they also offer support for drawing text and simple shapes.

OpenGL rendering often makes use of the view classes defined by the application frameworks UIKit and AppKit; when it does, some aspects of the drawing model are similar to that for native rendering. However, OpenGL applications do not have to be based on views.

Note: The information that follows describes aspects of the drawing model for native rendering. For information about OpenGL and OpenGL ES, consult the OpenGL website at  http://www.opengl.org/.


iOS 和 OS X的绘图是遵循下面两个技术之一并且是基于一个要求更新它们视图模型的外观的基础。你可以使用OpenGL或者是原生的渲染技术。

  • OpenGL. OpenGL  : 是一种基于C的接口来提供创建2D或者3D的桌面内容。它是一种非常理想的沉浸式的类型对于应用来说,例如游戏,或者是要求高frame比率的应用来说。对于OS X,有desktop版本的OpenGL框架;对于iOS,有OpenGL ES框架,这一种对嵌入式硬件系统的优化。
  • Native support.  : Quartz (Core Graphics), Core Animation, 和 application frameworks 对每一个平台 (UIKit and AppKit) 提供了原生的基于面向对象的图形支持。Quartz是一种主流的绘图接口,提供了机遇路径的绘制,抗锯齿的渲染技术,渐变的填充图案,图像,色调,坐标空间的转换,和PDF文档的创建,展示和解析。你可以使用Core Animation来动画演示不同的视图属性的变化和如何实现自定义动画。UIKit 和 AppKit都拥有代表图形实体的Object-C类例如图像,颜色和bezier曲线;它们也提供了绘制文字和简单形状的支持。
OpenGL的渲染经常很好地利用了应用框架UIKit和AppKit定义的view类别;当它执行的时候,绘图模型的一些方面与本地渲染非常相似。然而,OpenGL应用不用建立在视图的基础上。


A View Draws Itself When Necessary in Its drawRect: Method

A major element of the drawing model is content updating on demand. A view draws its content in the drawRect: method, which the view base class (UIView anda target="_self" NSView/a) declares and a view subclass overrides. The rectangle passed into the method identifies the area of the view that needs to be redrawn. The first time a view appears in a window, the rectangle matches the bounds of the view and the view draws all of its content. Subsequently, the view draws itself only when necessary and draws only that part of itself that has changed.

绘图模型的一个重要的因素就是内容的要求更新。一个视图是在方法drawRect:中绘制它的内容,它是view的基础类(UIView 和 a target="_self" NSView/a)声明了和一个view子类的重载。这个矩形传入这个方法定义了一个需要被重绘的视图的区域。首先一个view在window里面出现,这个矩形适配了这个视图的界面并且这个视图绘制它的所有内容。接下来,视图绘制它本身仅仅当是必要的时候并且绘制的仅仅是那部分发生改变的地方。


上面的图非常形象把,当没有发生改变的时候不会去调用drawRect:方法,当灯色发生改变的时候,因为要改变的只有背景颜色,所以改变的仅仅是背景。


Several actions can trigger a view update:

  • Code makes a previously hidden view visible again by setting itshidden property to NO.
  • Code explicitly invalidates a view To invalidate a view, and thus mark it for redrawing, you call methods such as setNeedsDisplay: ora target="_self" setNeedsDisplayInRect:/a on the view.
  • For views that are not layer-backed, the user moves or removes a view that was partially obscuring another view.
  • For views that are not layer-backed, the user scrolls a view off the containing scroll view and then scrolls it back on.

The presence of Core Animation layers affects the drawing behavior of views. Layers let a view cache its contents in a bitmap, which can then be manipulated without requiring extra drawing. All views in iOS are layer-backed. In OS X, you must opt-in to layer backing by enabling support for it in your view hierarchies. In OS X, you can also specify the redraw policy that is most efficient for your layer-backed views.

At the end of a cycle of the main event loop, a window proceeds down its view hierarchy and requests these views to draw themselves by calling theirdrawRect: methods.

有几种触发视图更新的操作:

  • 代码中通过设置一个早前设置成隐藏的视图的hidden属性为NO来控制它重新可视。
  • 代码中明确地使一个视图成为无效,因此标志为重绘当中,你在视图中调用方法例如:setNeedsDisplay: or a target="_self" setNeedsDisplayInRect:/a。
  • 对于一些没有层支持的视图, 用户移动或者删除一个视图会局部地遮挡着其他视图。
  • 对于一些没有层支持的视图,用户滚动视图偏离这个包含滚动视图的容器并且将它滚回来。
Core Animation层的出现影响了视图的绘制表现。层让一个视图缓存它的内容于一个位置,这可以不需要额外的绘制要求来操作。在iOS下所有视图都是基于layer的。在OS X系统下,你必须选择参加layer的支持通过启动对它的视图继承的支持。在OS X,你还可以确定这个重绘机制而且这是对于你的layer-backed最为有效的。

在主事件循环的末端,一个窗口沿着它的视图继承结构继续并且请求这些视图去绘制他们通过它们的方法:drawRect:。


A Graphics Context Sets the Drawing Environment

UIView andNSView automatically configure the drawing environment of a view before itsdrawRect: method is invoked. (In the AppKit framework, configuring the drawing environment is called locking focus.) As part of this configuration, the view class creates a graphics context for the current drawing environment.

This graphics context is a Quartz object (CGContext) that contains information the drawing system requires, such as the colors to apply, the drawing mode (stroke or fill), line width and style information, font information, and compositing options. (In the AppKit, an object of thea target="_self" NSGraphicsContext/a class wraps aCGContext object.) A graphics context object is associated with a window, bitmap, PDF file, or other output device and maintains information about the current state of the drawing environment for that entity. A view draws using a graphics context associated with the view’s window. For a view, the graphics context sets the default clipping region to coincide with the view’s bounds and puts the default drawing origin at the origin of a view’s boundaries.


UIView和NSView自动地配置视图的绘制环境在调用drawRect:之前。(在AppKit框架,配置绘制环境被称为locking focus:锁定焦点。)作为配置的一部分,视图类创建了一个图形上下文给当前的绘图环境。

这个图形上下文是一个Quartz对象(CGContext),它包含了绘图系统需要的信息,例如作为要提供的色调,绘图模式(stroke:绘制当前路径的边框或者填充),线条宽度和样式信息,字体信息和复合选项。(在AppKit中,一个对象:a target="_self" NSGraphicsContext/a 包裹了CGContext 对象。)一个图形上下文对象和window,位图,PDF文件或者其他输出设备还有维护该绘图环境中的实体的当前状态有联系。一个视图绘画使用了图形上下文是与该视图的窗口有联系的。对于一个视图,图形上下文设置了默认地裁减区域来与视图的边界重合并且放置了默认的绘制原点在视图的界面的原理(坐标系对齐)。


Drawing Takes Place in a View’s Local Coordinate System

A view draws itself in its local coordinate system. The view’s bounds property serves to define the location of points in this coordinate system.

You can change a view’s default coordinate system by modifying the current transformation matrix (CTM). The CTM maps points in a view’s coordinate system to points on the device’s screen. By changing the CTM, you can modify the size, orientation, and position of a view’s coordinate system relative to its superview or window, thereby scaling, rotating, or moving the view.

Drawing commands make reference to a fixed-scale drawing space, known as the user coordinate space. The operating system maps coordinate units in this drawing space onto the actual pixels of the corresponding target device. Thus vector commands issued by a view scale to any resolution supported by the device. These commands specify drawing coordinates using floating-point values to acquire the precision required for vector-based drawing.


一个视图绘制它本身在本地的坐标体系上。视图的界面属性用来定义点的位置在它的坐标系上。

你可以改变视图的默认坐标系通过修改当前的transformation matrix:变换矩阵(CTM)。CTM映射点在视图的坐标系来指出设备的屏幕。通过改变CTM,你可以修改大小,屏幕方向和视图在坐标系上相对于父类或者窗口的位置,从而缩放,旋转或者移动这个视图。

绘图命令参考了一个固定比例的绘图空间,称为用户坐标体系。操作系统将这个坐标单元映射到这个绘图空间成一个真实的相关目标的像素。通过视图比例由设备支持的任何决议发出任何的这样的命令载体。这些命令明确了绘图坐标系统使用浮点值来获得准确的基于矢量的绘图要求。


关于绘图,官方文档有一篇更加详述的介绍:iOS Drawing Concepts,等UIView绘图专题再做介绍。



0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:79789次
    • 积分:4417
    • 等级:
    • 排名:第7210名
    • 原创:374篇
    • 转载:7篇
    • 译文:4篇
    • 评论:4条
    最新评论