您的位置:首页 > 产品设计 > UI/UE

iOS文档-UIView的基本属性

2014-02-14 21:57 253 查看
注:以下内容为本人根据苹果官方文档加上自己的理解写成。

UIView
#苹果官方文档对UIView(UIViewGeometry)的描述如下:
  // animatable. do not use frame if view is transformed 
  //since it will not correctly reflect the actual location of the view. 
  //use bounds + center instead.
  大概意思就是:frame是可动画属性,当view发生形变时,而如果它不能正确表示出view的实际位置,
  就是用bounds与center的组合代替.
^四大基本属性^
  1.frame : origin && size : x,y && width,height
  UIView *_myView = [[UIView alloc] init]; 
  由于OC语法规定,不允许直接修改 某个对象中结构体属性的成员,因此对frame属性操作一般如下
  Step 1>.取出view的frame
  		 CGRect tempFrame = _myView.frame;
  	   2>.对tempFrame进行具体操作
  	   3>.重新赋值给原来的frame
  	   _myView.frame = tempFrame;
  #对frame属性的描述如下:
  // use bounds/center and not frame if non-identity transform. 
  //if bounds dimension is odd, center may be have fractional part
  大概意思就是: 如果transform属性为非同一性,使用bounds或者center属性。
  如果bounds的尺寸是奇数,center可能会有小数部分.

  2.bounds: origin 一般都是(0,0) ,size : width && height
  #对bounds属性的描述如下:
  // default bounds is zero origin, frame size. animatable

  3.center: 是frame属性的中点
  #对center属性的描述如下:
  // center is center of frame. animatable

  4.transform:形变属性
  #对transform属性的描述如下:
  // center is center of frame. animatable
  // default is CGAffineTransformIdentity. animatable
  
  CGAffineTransform结构体定义如下
  typedef struct CGAffineTransform CGAffineTransform;
  struct CGAffineTransform {
  CGFloat a, b, c, d;
  CGFloat tx, ty;
};

  *切记,frame属性与center属性的原点(0,0)是父控件的左上角。
  *只有bounds属性的原点是自己的左上角。

  PS:
  CGRect 有2个成员,分别是 CGFloat,CGSize 两个结构体
  其定义如下:
  //CGRect的定义
  struct CGRect {
  CGPoint origin;
  CGSize size;
	};
  typedef struct CGRect CGRect;
  //CGPoint的定义
  struct CGPoint {
  CGFloat x;
  CGFloat y;
	};
  typedef struct CGPoint CGPoint;
  //CGSize的定义
  struct CGSize {
  CGFloat width;
  CGFloat height;
	};
  typedef struct CGSize CGSize;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: