Hierarchy[‘ha??rɑ?k?]n.層級
思考:每個視圖有一個父視圖,有0個或者多個子視圖
Manipulation[m?,n?pj?‘le??(?)n] n.操縱;操作
Descendant[d?‘send(?)nt] n.
後裔;子孫
UIWindow
Feature:
1、UIWindow set up by default in Xcodetemplate project,and contains the entire view
hierarchy
2、UIWindow just a view,and adds someadditional to top level view
3、Views live inside of a window
思考:UIWIndow位于toplevel,啟動APP的時候首先啟動,其他所有在上面的View依次渲染出現
Principle
UIView的屬性
思考:每一個View都有一個superview,有一個對應的subviews(注意是NSArraay),有一個window.所有對子視圖的操作,其實本質上來講也就是對數組的操作。視圖的增删改,對應的就是數組的增删改。當然也有視圖的回調方法用于跟蹤視圖改變。
ViewManipulation
1、add or remove in IB or using UIVIew methods
(void)addSubview:(UIView *)view;
(void)removeFromSuperview;
示例:
思考:上圖很清楚的看出來,視圖的層次關系是:UIWindow -> View_blue -> View_yellow
此時如果更改添加順序,代碼和效果圖如下:
思考:很明顯現在的視圖層次是:UIWindow -> View_yellow-> View_blue,此時self.window.subviews列印的結果是:
views:(
"<UIView:0x8f1ecc0; frame = (50 50; 100 100); layer = <CALayer:0x8f1ed20>>",
"<UIView:0x8f13330; frame = (0 0; 100 100); layer = <CALayer: 0x8f1d800>>"
)
3、otherViewmanipulationmethods
思考:每一個View的子視圖其實就是一個數組,對View的子視圖的操作也就是對目前view的子視圖數組進行操作。常見的操作無非尾部增加、特定位置增加、删除、調整在數組中的位置、調換2個數組元素的位置而已。
思考:上面的[self.windowinsertSubview:view_redatIndex:0];這句話其實就是把紅色的view添加到UIWindow子視圖數組的第1個位置,是以位于blue、yellow的下層
如果在這句話[self.windowinsertSubview:view_redatIndex:0];後面加上這句話
[self.windowinsertSubview:view_redatIndex:0];那麼産生的效果如下:
思考:其實本質都是對UIWIndow子視圖數組的操作
4、Tracks theadditions and removals of subviews
思考:視圖回調主要是用于跟蹤視圖的相關改變
5、Set view tag and search view
myView.tag = 1011;
UILabel *label =(UILablel *)[self.view viewWithTag:1011];
6、isDescendantOfView
- (BOOL)isDescendantOfView:(UIView
*)view;
思考:主要用于判斷的一個View是不是另一個View的子subView