概述
UIView對象在屏幕中定義了一個復(fù)雜區(qū)域和界面來管理這個區(qū)域的內(nèi)容
視圖的職責(zé):畫圖和動畫。布局和子視圖管理。事件處理。
1、創(chuàng)建一個視圖對象
CGRect viewRect = CGRectMake(10,10,100,100);UIView* myView = [[UIView alloc] initWithFrame:viewRect];[self.window addSubview :myView];//將視圖作為子視圖添加到window中2、動畫
改變一些視圖屬性將會使用到動畫,改變屬性時創(chuàng)建一個動畫,用于給用戶傳遞在較短時間內(nèi)的變化。UIView類做了動畫展現(xiàn)的大部分工作,但是你仍然需要聲明哪種屬性改變的時候,你需要動畫效果。有兩種不同的類型來初始化動畫下面的UIView屬性支持動畫:frame,bounds,center,transform,alpha,backgroundColor,contentStretch在iOS 4之后,使用block-based動畫方法(推薦使用)使用 開始/提交方式(begin/commit)3、管理視圖的層次結(jié)構(gòu)
superview屬性:subviews屬性:window屬性:-addSubview方法-bringSubviewToFront:(UIView *)veiw方法,將view視圖移到層次結(jié)構(gòu)的最頂端,使得其得以展示-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是不是指定視圖的子視圖4、子視圖的布局(layout)
-layoutSubviews方法,這個方法,默認沒有做任何事情,需要子類進行重寫-setNeedsLayout方法-layoutIfNeeded方法,立即對子視圖進行布局5、畫/更新視圖
-drawRect:(CGRect)rect方法-setNeedsDisplay-setNeedsDisplayInRect:(CGRect)invalidRect方法6、以塊展現(xiàn)動畫的方式(animating views with block)
+ animateWithDuration:delay:options:animations:completion:+ animateWithDuration:animations:completion:+ animateWithDuration:animations:+ transitionWithView:duration:options:animations:completion:+ transitionFromView:toView:duration:options:completion:
7、在視圖和坐標系統(tǒng)之間轉(zhuǎn)換
-convertPoint:toView-convetPoint:fromView-convertRect:toView-convertRect:fromView8、跟蹤視圖相關(guān)的改變
-didAddSubview:-willRemoveSubview:-willMoveToSuperview-didMoveToSuperview-willMoveToWindow:-didMoveToWindow