UIView介绍

1.什么是视图

      视图是屏幕上的一个矩形区域。它有两个用途:第一个用途是在上面绘制内容,第二个用途是处理事件。

2.视图在iphone上是分层排列的,每个视图只有一个父视图,但有零个或多个子视图。

3.UIWindow是唯一没有父视图的视图,一个应用只有一个UIWindow。

4.操作视图层次的方法

  - (void)addSubView:(UIView *)view;

  - (void)removeFromSuperview;

  - (void)insertSubView:(UIView *)view atIndex:(int)index;

  - (void)insertSubview:(UIView *)view belowSubview:(UIView *)siblingSubview;

  - (void)insertSubview:(UIView *)view aboveSubview:(UIView *)siblingSubview;

  - (void)exchangeSubviewAtIndex:(NSInteger)index1 withSubviewAtIndex:(NSInteger)index2;

5.视图相关的结构体

 CGPoint     CGSize      CGRect

6.frame与bounds的区别

 frame是视图在其父视图坐标系统中的大小和位置

 bounds是视图在自身坐标系中的大小和位置

7.自定义视图,需要重写

- (void)drawRect:(CGRect)rect;

但永远不要直接调用上面的方法,而是调用下面的方法来通知系统重画视图

- (void)setNeedsDisplay;

8.处理事件的方法

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event;

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;

- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event;

 

posted @ 2013-02-05 23:34  重生2013  阅读(568)  评论(0编辑  收藏  举报