IOS UIView Basic Attribute Usage

Source: Internet
Author: User

1.创建 UIView       UIView * redView = [[ UIView alloc] initWithFrame:CGRectMake(10, 100, 200, 100)];       UIView * blueView = [[ UIView alloc] init];        把blueView粘贴到了redView上      [redView addSubview:blueView];            redView 就是blueView 的父视图         修改父视图属性 对子视图产生影响 2.设置隐藏      redView.hidden = YES ; //父视图隐藏子视图也会隐藏 3.如果子视图超出父视图范围是否裁剪子视图  默认是 NO      redView.clipsToBounds = YES ; 4.是否可以和用户进行交互,默认为 YES      redView.userInteractionEnabled = YES ;      UIView 默认 YES      /*       如果可一个用户交互那么这个视图 可以接收点击,子视图也可以接收点击事件       谁在在上方谁想接受点击 最上方的会拦截       如果设置为NO 子视图和父视图都不能接受点击事件,那么这个点击就会向下层传递知道能被接受事件的控件接收 如果最后没有控件接受这个事件 事件将会被抛弃          UILabel UIIImageView userInteractionEnabled默认是NO,不可以和用户进行交互          如果button 粘贴到UILabel 和UIIImageView上 button是不能被点击          如果想要能点击button 就要把UILabel 和 UIIImageView 的userInteractionEnabled改为YES       */ 5.确定父子视图关系之后我们就可以获取所有的子视图      NSArray * subViews = redView.subviews; 6.获取子视图的父视图      UIView * superView = blueView.superview; 7.判断一个视图是否是另外一个视图的子视图      [button isDescendantOfView:redView]; 8.在指定的索引位置插入一个子视图(这个函数也会把子视图粘贴到父视图上)              如果指定的索引超出了 父视图对应的索引值 那么就会把这个子视图插在 最上层          索引0 对应的就是最底层      [ self .view insertSubview:label4 atIndex:10]; 9.在指定的某个子视图下方插入一个新的子视图      [ self .view insertSubview:label4 belowSubview:label1];      10.在指定的某个子视图上方插入一个新的子视图      [ self .view insertSubview:label4 aboveSubview:label1]; 11.父视图 把指定的子视图 放到最前方      [ self .view bringSubviewToFront:label4]; 12.父视图 把指定的两个视图进行交换      [ self .view exchangeSubviewAtIndex:0 withSubviewAtIndex:2]; 13.父视图 把指定的子视图放到最底层      [ self .view sendSubviewToBack:label4]; 14.可以通过设置中心点位置      blueView.center = CGPointMake(100, 100); 15.通过bounds 改变 视图的边框大小      blueView.bounds = CGRectMake(0, 0, 100, 100);      //bounds 前两项一般是 0 0      frame 和 bounds 区别       1.frame 子视图相对于父视图的坐标系的坐标       2.bounds 前两项的坐标是相对于自己坐标系的坐标       3.如果把bounds 中的坐标改变了 那么就会影响自己的坐标系,那么最终能影响子视图 16.修改view的bounds会将redView的坐标系改变      redView.bounds = CGRectMake(-50, -50, 200, 100); 17.view.transform        1.CGAffineTransformMakeRotation 设置视图的旋转角度(这个角度相对最原始的位置)       imagebutton.transform = CGAffineTransformMakeRotation(M_PI/4);                       2.CGAffineTransformRotate函数相对于当前imagebutton.transform 旋转的角度      imagebutton.transform = CGAffineTransformRotate(imagebutton.transform, M_PI/4);   18.CGAffineTransformMakeScale可以实现 放大 缩小 上下翻转 左右翻转            都是相对最原始的状态进行变换               CGAffineTransformMakeScale(x, y);               x 控制x 方向的大小  1 原始大小 >1 x方向放大  <1 缩小               y 控制 y方向 大小   1  原始大小 >1 y纵向放大  < 1缩小                           x 是负数 表示相对于原始的位置 左右翻转 翻转180度               x 是正数    原始的位置                           y 负数  相对于原始的位置  上下翻转               y 正数 就是最原始的位置       imagebutton.transform = CGAffineTransformMakeScale(-2, 2); 19.动画      [ UIView animateWithDuration:0.25 animations:^{ //执行的第一个动画      } completion:^( BOOL finished) { //第一个动画结束时执行      }] 20.设置父子视图自适应/停靠模式      _redView.autoresizesSubviews = YES ; //允许子视图伴随父视图自动变化 21.设置子视图的自适应模式      blueView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin ;      /*       UIViewAutoresizingFlexibleLeftMargin   = 1 << 0,       父子视图的左边距 会伴随父视图的宽度 增加而增加 减少而减少       UIViewAutoresizingFlexibleWidth        = 1 << 1,       //子视图的宽度会伴随父视图的宽度增加而增减 减少而减少       UIViewAutoresizingFlexibleRightMargin  = 1 << 2,       父子视图的右边距 会伴随父视图的宽度 增加而增加 减少而减少       UIViewAutoresizingFlexibleTopMargin    = 1 << 3,       父子视图的上边距 会伴随父视图的宽度 增加而增加 减少而减少       UIViewAutoresizingFlexibleHeight       = 1 << 4,       //子视图的高度会伴随父视图的高度增加而增减 减少而减少       UIViewAutoresizingFlexibleBottomMargin = 1 << 5       父子视图的下边距 会伴随父视图的宽度 增加而增加 减少而减少       */

IOS UIView Basic Attribute Usage

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.