iOS开发之-View 1-View and Window Architecture

本文介绍了iOS中视图(View)与窗口(Window)的基本概念及其工作原理,包括视图的绘制周期、内容模式、拉伸视图、内置动画支持等内容,并详细解释了视图几何与坐标系统的相关知识点。

1. Windows do not have any visible content themselves but provide a basic container for your application’s views. 

2.Views are responsible for drawing content, handling multitouch events, and managing the layout of any subviews. Drawing involves using graphics technologies such as Core Graphics, OpenGL ES.

3. In the view hierarchy, parent views are responsible for positioning and sizing their child views and can do so dynamically.

4. If an external display is connected to the device, applications can create a second window to present content on that screen as well.

5. UIView's designated initializer is initWithFrame:

6. Also, you can hide a view completely by setting hidden property @property (nonatomic) BOOL hidden;
myView.hidden = YES;



View and Window Architecture

1. Views work in conjunction with Core Animation layers to handle the rendering and animating of a view’s content. Every view in UIKit is backed by a layer object (usually an instance of the CALayer class), which manages the backing store for the view and handles view-related animations.



2. Every view has a corresponding layer object that can be accessed from that view’s layer property. Behind those layer objects are Core Animation rendering objects and ultimately the hardware buffers used to manage the actual bits on the screen.

3.  The actual drawing code of a view object is called as little as possible, and when the code is called, the results are cached by Core Animation and reused as much as possible later. 


View Hierarchies and Subview Management

1. A view can act as a container for other views. When one view contains another, a parent-child relationship is created between the two views. 

2. Each superview stores its subviews in an ordered array and the order in that array also affects the visibility of each subview.

3.  Changing the size of a parent view has a ripple effect that can cause the size and position of any subviews to change too. 

The View Drawing Cycle


1. The UIView class uses an on-demand drawing model for presenting content. When a view first appears on the screen, the system asks it to draw its content. The system captures a snapshot of this content and uses that snapshot as the view’s visual representation.

2. When the contents of your view change, you do not redraw those changes directly. Instead, you invalidate the view using either the setNeedsDisplay or setNeedsDisplayInRect: method. These methods tell the system that the contents of the view changed and need to be redrawn at the next opportunity. 

3. The system waits until the end of the current run loop before initiating any drawing operations. This delay gives you a chance to invalidate multiple views, add or remove views from your hierarchy, hide views, resize views, and reposition views all at once. All of the changes you make are then reflected at the same time.

4. For custom UIView subclasses, you typically override the drawRect: method of your view and use that method to draw your view’s content.

Content Modes

1. Each view has a content mode that controls how the view recycles its content in response to changes in the view’s geometry and whether it recycles its content at all.


2. The content mode of a view is applied whenever you do the following:

(1)Change the width or height of the view’s frame or bounds rectangles.
(2)Assign a transform that includes a scaling factor to the view’s transform property.


3.By default, the contentMode property for most views is set to UIViewContentModeScaleToFill



4. 视图几何大小的改变不会引起系统调用drawRect方法


 

Stretchable Views

1.You can designate a portion of a view as stretchable so that when the size of the view changes only the content in the stretchable portion is affected. 


2.You specify the stretchable area of a view using the contentStretch property. This property accepts a rectangle whose values are normalized to the range 0.0 to 1.0. 


3. 

Built-In Animation Support

1. One of the benefits of having a layer object behind every view is that you can animate many view-related changes easily. 

2. Many properties of the UIView class are animatable. To perform an animation for one of these animatable properties, all you have to do is:
   (1) Tell UIKit that you want to perform an animation.
   (2) Change the value of the property.

3. Among the properties you can animate on a UIView object are the following:
    frame—Use this to animate position and size changes for the view.
    bounds—Use this to animate changes to the size of the view.
    center—Use this to animate the position of the view.
    transform—Use this to rotate or scale the view.
    alpha—Use this to change the transparency of the view.
    backgroundColor—Use this to change the background color of the view.
    contentStretch—Use this to change how the view’s contents stretch.

View Geometry and Coordinate Systems



1. In addition to the screen coordinate system, windows and views define their own local coordinate systems that allow you to specify coordinates relative to the view or window origin instead of relative to the screen.

2. The UIWindow and UIView classes both include methods to help you convert from one coordinate system to another.

The Relationship of the Frame, Bounds, and Center Properties


1. A view object tracks its size and location using its frame, bounds, and center properties:

---The frame property contains the frame rectangle, which specifies the size and location of the view in its superview’s coordinate system.

---The bounds property contains the bounds rectangle, which specifies the size of the view (and its content origin) in the view’s own local coordinate system.

---The center property contains the known center point of the view in the superview’s coordinate system.



2. By default, a view’s frame is not clipped to its superview’s frame. Thus, any subviews that lie outside of their superview’s frame are rendered in their entirety. You can change this behavior, though, by setting the superview’s clipsToBounds property to YES. 

Coordinate System Transformations

1. An affine transform is a mathematical matrix that specifies how points in one coordinate system map to points in a different coordinate system.

2. You typically modify the transform property of a view when you want to implement animations. When modifying the transform property of your view, all transformations are performed relative to the center point of the view.

3. One point does not necessarily correspond to one pixel on the screen.

The Runtime Interaction Model for Views

1. 



评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值