UIView*view1=[[UIView alloc]initWithFrame:CGRectMake(10,30,300,30)];

view1.backgroundColor=[UIColor redColor];
[self.window addSubview:view1];
[view1 release];
 
UIView*view2=[[UIView alloc]init];
view2.frame=CGRectMake(30,20,50,100);
view2.backgroundColor=[UIColor blueColor];
[self.window addSubview:view2];
[view2 release];
 
UIView*view3=[[UIView alloc]initWithFrame:CGRectMake(20,50,200,200)];
view3.backgroundColor=[UIColor yellowColor];
[self.window addSubview:view3];
//把某一个view放到最下层
[self.window sendSubviewToBack:view2];
//把某一个view放到最上层
[self.window bringSubviewToFront:view2];
//把某一个view加入到指定层
[self.window insertSubview:view2 atIndex:1];
//把某一个view加入到某层的下面
[self.window insertSubview:view2 belowSubview:view1];
//把某一个view加入到某层的上面
[self.window insertSubview:view2 aboveSubview:view1];
//交换两个层的view
[self.window exchangeSubviewAtIndex:0 withSubviewAtIndex:1];
 
//自动布局模式(停靠模式)
//前面把_backgroundView设置成了成员变量,为了方便,没有写出来
_backgroundView=[[UIView alloc]initWithFrame:CGRectMake(110,300,100,100)];
_backgroundView.background=[UIColor blackColor];
//设置父view允许子view自动布局
_backgroundView.autoresizesSubviews=YES;
[self.window addSubview:_backgroundView];
 
UIView*topView=[[UIView alloc]initWithFrame:CGRectMake(25,25,50,50)];
topView.backgroundColor=[UIColor orangeColor];
//设置子view的自动布局模式
//下面设置会让topView跟着_backgroundView变化而变化,中心点不变
topView.autoresizingMask=UIViewAutoresizingFlexibleBottomMargin|UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin|UIViewAutoresizingFlexibleTopMargin|UIViewAutoresizingFlexibleWidth;
[_backgroundView addSubview:topView];
//创建一个按钮,点一下,_backgroundView会变大
UIButton*btn=[UIButton buttonWithType:UIButtonTypeRoundedRect];
btn.frame=CGRectMake(10,230,300,20);
[btn addTarget:self action:@selector(click) forControlEvents:UIControlEventTouchUpInside];
[self.window addSubview:btn];
 
-(void)click
{
_backgroundView.frame=CGRectMake(_backgroundView.frame.origin.x-2,_backgroundView.frame.orgin.y-2,_backgroundView.frame.size.width+4,_backgroundView.frame.height+4);
}

UIView的层次调整,及子view布局模式自动布局模式(停靠模式)的更多相关文章

  1. IOS UIView 03- 自定义 Collection View 布局

    注:本人是翻译过来,并且加上本人的一点见解. 前言 UICollectionView 在 iOS6 中第一次被引入,也是 UIKit 视图类中的一颗新星.它和 UITableView 共享一套 API ...

  2. View事件传递之父View和子View之间的那点事

    Android事件传递流程在网上可以找到很多资料,FrameWork层输入事件和消费事件,可以参考: Touch事件派发过程详解 这篇blog阐述了底层是如何处理屏幕输,并往上传递的.Touch事件传 ...

  3. LinearLayout的gravity属性以及其子元素的layout_gravity何时有效;RelativeLayout如何调整其子元素位置只能用子元素中的属性来控制,用RelativeLayout中的gravity无法控制!!!

    LinearLayout的gravity属性以及其子元素的layout_gravity何时有效:RelativeLayout如何调整其子元素位置只能用子元素中的属性来控制,用RelativeLayou ...

  4. 15-UIKit(view布局、Autoresizing)

    目录: 1. 纯代码布局 2. 在View中进行代码布局 3. Autoresizing 回到顶部 1. 纯代码布局 纯代码布局分VC下和V下 [MX1-layout-code] 在VC下覆盖view ...

  5. viewpager与子view的事件冲突解决

    问题: 对android的事件机制一直不怎么了解,最近android项目中运用viewpager+listview (就是viewpager的子view中嵌套了listview),出现了触摸手势冲突 ...

  6. Android View框架总结(六)View布局流程之Draw过程

    请尊重分享成果,转载请注明出处: http://blog.csdn.net/hejjunlin/article/details/52236145 View的Draw时序图 ViewRootImpl.p ...

  7. Android View框架总结(五)View布局流程之Layout

    转载请注明出处:http://blog.csdn.net/hejjunlin/article/details/52216195 View树的Layout流程 View的Layout时序图 View布局 ...

  8. Android View框架总结(四)View布局流程之Measure

    View树的measure流程 View的measures时序图 View布局流程之measure measure过程 View的measure过程 ViewGroup的measure过程 Frame ...

  9. Listview自定义了子View导致listview的onitemclick事件无效

    原因是子View的点击事件抢占了listview的点击事件 解决办法: 1. 子View根布局 设置 android:descendantFocusability="blocksDescen ...

随机推荐

  1. spring espect XX but YY

    注入和查找问题 HSF Consumer bean, 注入的是beanName='实际接口名', type='HSFSpringConsumerBean',  造成Autowire时查询出来的类型不匹 ...

  2. Java学习笔记day04_数组

    1.switch case switch语句中表达式的数据类型是有要求的: JDK 1.0 ~ 1.4 , 数据类型接受byte, short, int, char JDK 1.5 , 数据类型接受b ...

  3. scanf()函数的注意事项

    /* 2 time:2018年5月23日18:57:52 3 author:Howie Tang 4 title:scanf()函数的总结 5 */ #include <stdio.h> ...

  4. my.常用的话

    1. 60普通副本+++ 60普通副本+++ 60普通副本+++ 50封妖+++50封妖+++50封妖+++ 60一本十妖+++ 60一本十妖+++ 60一本十妖+++ 60封妖+++60封妖+++6 ...

  5. Spring MVC自定义错误页面

    在web.xml中添加: <error-page(其他属性404...省略咯)> <location>/error</location> </error-pa ...

  6. Mockjs详细使用说明

    Mock.js 是一款前端开发中拦截Ajax请求再生成随机数据响应的工具.可以用来模拟服务器响应. 优点是非常简单方便, 无侵入性, 基本覆盖常用的接口数据类型. 在我们的生产实际中,后端的接口往往是 ...

  7. qt的signal和slot机制

    signal和slot是QT中的一大特点 signal/slot是Qt对象以及其派生类对象之间的一种高效通信接口 用户可以将N多个信号和单个槽相连接, 或者将将N个槽和单个信号连接, 甚至是一个信号和 ...

  8. Python + Selenium 练习篇 - 获取页面所有邮箱

    代码如下: # coding=utf-8import re    #python中利用正则,需要导入re模块from selenium import webdriverdriver = webdriv ...

  9. 通过navigator.userAgent判断浏览器类型

    1.navigator.userAgent返回一个浏览器信息字符串. 2.用到indexOf()方法,查找字符串中是否有指定的浏览器类型. 3. if(navigator.userAgent.inde ...

  10. input类型为file改变默认按钮样式

    改变 input file 样式(input  文件域)是很多前端朋友经常遇到的头疼问题,今天推荐两种改变 input file 样式的两种常用方法: 方法一: <input type=&quo ...