概述

UIView对象在屏幕中定义了一个复杂区域和界面来管理这个区域的内容布局

视图的职责:
画图和动画。
布局和子视图管理。动画

事件处理。orm

 

一、建立一个视图对象

CGRect viewRect = CGRectMake(10,10,100,100);
UIView* myView = [[UIView alloc] initWithFrame:viewRect];
[self.window addSubview :myView];//将视图做为子视图添加到window中对象

二、动画

改变一些视图属性将会使用到动画,改变属性时建立一个动画,用于给用户传递在较短期内的变化。UIView类作了动画展示的大部分工做,可是你仍然须要声明哪一种属性改变的时候,你须要动画效果。有两种不一样的类型来初始化动画
下面的UIView属性支持动画:
frame,bounds,center,transform,alpha,backgroundColor,contentStretch
在iOS 4以后,使用block-based动画方法(推荐使用)
使用 开始/提交方式(begin/commit)事件

三、管理视图的层次结构

superview属性:
subviews属性:
window属性:
-addSubview方法
-bringSubviewToFront:(UIView *)veiw方法,将view视图移到层次结构的最顶端,使得其得以展现
-sendSubviewToBack:(UIView *)veiw方法,和上面方法正好相反
-removeFromSupview方法,
-insertSubview:(UIView *)view atIndex:(Interger)index方法
-insertSubview:(UIView *)view aboveSubview(UIView *)siblingView 方法
-insertSubview:(UIView *)view belowSubview(UIView *)siblingView 方法
-exchangeSubviewAtIndex:(NSInteger)index1 withSubviewAtIndex:(NSInteger)index2方法
-isDescendantOfView:(UIView *)view方法,判断view是否是指定视图的子视图rem

四、子视图的布局(layout)

-layoutSubviews方法,这个方法,默认没有作任何事情,须要子类进行重写
-setNeedsLayout方法
-layoutIfNeeded方法,当即对子视图进行布局animation

五、画/更新视图

-drawRect:(CGRect)rect方法
-setNeedsDisplay
-setNeedsDisplayInRect:(CGRect)invalidRect方法it

六、以块展示动画的方式(animating views with block)

+ animateWithDuration:delay:options:animations:completion:
+ animateWithDuration:animations:completion:
+ animateWithDuration:animations:
+ transitionWithView:duration:options:animations:completion:io

+ transitionFromView:toView:duration:options:completion:form

七、在视图和坐标系统之间转换

-convertPoint:toView
-convetPoint:fromView
-convertRect:toView
-convertRect:fromView

八、跟踪视图相关的改变

-didAddSubview:-willRemoveSubview:-willMoveToSuperview-didMoveToSuperview-willMoveToWindow:-didMoveToWindow

相关文章
相关标签/搜索