概述

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

相關文章
相關標籤/搜索