一點一滴,編程人生

            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
            69 隨筆 :: 0 文章 :: 25 評論 :: 0 Trackbacks

          概述

          UIView對象在屏幕中定義了一個復雜區域和界面來管理這個區域的內容

          視圖的職責:
          畫圖和動畫。
          布局和子視圖管理。

          事件處理。

           

          1、創建一個視圖對象

          CGRect viewRect = CGRectMake(10,10,100,100);
          UIView* myView = [[UIView alloc] initWithFrame:viewRect];
          [self.window addSubview :myView];//將視圖作為子視圖添加到window中

          2、動畫

          改變一些視圖屬性將會使用到動畫,改變屬性時創建一個動畫,用于給用戶傳遞在較短時間內的變化。UIView類做了動畫展現的大部分工作,但是你仍然需要聲明哪種屬性改變的時候,你需要動畫效果。有兩種不同的類型來初始化動畫
          下面的UIView屬性支持動畫:
          frame,bounds,center,transform,alpha,backgroundColor,contentStretch
          在iOS 4之后,使用block-based動畫方法(推薦使用)
          使用 開始/提交方式(begin/commit)

          3、管理視圖的層次結構

          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是不是指定視圖的子視圖

          4、子視圖的布局(layout)

          -layoutSubviews方法,這個方法,默認沒有做任何事情,需要子類進行重寫
          -setNeedsLayout方法
          -layoutIfNeeded方法,立即對子視圖進行布局

          5、畫/更新視圖

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

          6、以塊展現動畫的方式(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、在視圖和坐標系統之間轉換

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

          8、跟蹤視圖相關的改變

          -didAddSubview:
          -willRemoveSubview:
          -willMoveToSuperview
          -didMoveToSuperview
          -willMoveToWindow:
          -didMoveToWindow
          posted on 2012-04-20 10:37 writegull 閱讀(9675) 評論(0)  編輯  收藏 所屬分類: iphone
          主站蜘蛛池模板: 盘山县| 辉南县| 沈阳市| 专栏| 西城区| 清远市| 天全县| 香河县| 侯马市| 巴马| 南投市| 长白| 霞浦县| 普兰店市| 桐乡市| 红河县| 监利县| 定兴县| 平顶山市| 扎鲁特旗| 秦安县| 泰州市| 万源市| 阳城县| 徐闻县| 吉木乃县| 宜昌市| 聂拉木县| 大兴区| 萝北县| 肥城市| 璧山县| 秦安县| 大化| 汽车| 西乌| 西畴县| 沈丘县| 绥芬河市| 忻州市| 子洲县|