图层的位置交换
view老版本视图的分解
view也可以进行增删改差
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
UIView *view = [[UIView alloc]initWithFrame:CGRectMake(100, 100, 414-100-10, 50)];
view.backgroundColor = [UIColor redColor];
//视图添加方法
[self.view addSubview:view];
UIView *view2 = [[UIView alloc]initWithFrame:CGRectMake(100, 200, 414-100-10, 50)];
view2.backgroundColor = [UIColor greenColor];
[self.view addSubview:view2];
}
@end
//xr 414*896
view重合
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
UIView *view = [[UIView alloc]initWithFrame:CGRectMake(100, 100, 414-100-10, 50)];
view.backgroundColor = [UIColor redColor];
//视图添加方法
[self.view addSubview:view];
UIView *view2 = [[UIView alloc]initWithFrame:CGRectMake(100, 100, 414-100-10, 50)];
view2.backgroundColor = [UIColor greenColor];
[self.view addSubview:view2];
}
@end
交换视图
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
UIView *view = [[UIView alloc]initWithFrame:CGRectMake(100, 100, 414-100-10, 50)];
view.backgroundColor = [UIColor redColor];
//视图添加方法
[self.view addSubview:view];
UIView *view2 = [[UIView alloc]initWithFrame:CGRectMake(100, 100, 414-100-10, 50)];
view2.backgroundColor = [UIColor greenColor];
[self.view addSubview:view2];
//exchangeSubviewAtIndex 新版本的xcode传入0,1;老版本传入2,3
[self.view exchangeSubviewAtIndex:1 withSubviewAtIndex:0];
//等价于[self.view exchangeSubviewAtIndex:0 withSubviewAtIndex:1];
}
@end
//xr 414*896
把某个视图插入到某个位置
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
UIView *view = [[UIView alloc]initWithFrame:CGRectMake(100, 100, 414-100-10, 50)];
view.backgroundColor = [UIColor redColor];
//视图添加方法
[self.view addSubview:view]; //index 0
UIView *view2 = [[UIView alloc]initWithFrame:CGRectMake(100, 100, 414-100-10, 50)];
view2.backgroundColor = [UIColor greenColor];
//把某个视图插入到某个位置
[self.view insertSubview:view2 atIndex:0];// index 0 红色, index 1 绿色
}
@end
//xr 414*896
把某个视图移到最前面
先创建3个视图
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
UIView *view = [[UIView alloc]initWithFrame:CGRectMake(100, 100, 414-100-10, 50)];
view.backgroundColor = [UIColor redColor];
//视图添加方法
[self.view addSubview:view]; //index 0 红色
UIView *view2 = [[UIView alloc]initWithFrame:CGRectMake(110, 110, 414-100-10, 50)];
view2.backgroundColor = [UIColor greenColor];
//把某个视图插入到某个位置
[self.view addSubview:view2];// index 1 绿色
UIView *view3 = [[UIView alloc]initWithFrame:CGRectMake(120, 120, 414-100-10, 50)];
view3.backgroundColor = [UIColor blueColor];
}
@end
//xr 414*896
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
UIView *view = [[UIView alloc]initWithFrame:CGRectMake(100, 100, 414-100-10, 50)];
view.backgroundColor = [UIColor redColor];
//视图添加方法
[self.view addSubview:view]; //index 0 红色
UIView *view2 = [[UIView alloc]initWithFrame:CGRectMake(110, 110, 414-100-10, 50)];
view2.backgroundColor = [UIColor greenColor];
//把某个视图插入到某个位置
[self.view addSubview:view2];// index 1 绿色
UIView *view3 = [[UIView alloc]initWithFrame:CGRectMake(120, 120, 414-100-10, 50)];
view3.backgroundColor = [UIColor blueColor];
//把某个视图插入到某个位置
[self.view addSubview:view3];//index 2 蓝色
[self.view bringSubviewToFront:view];//把红色的视图移到最前面
}
@end
//xr 414*896
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
UIView *view = [[UIView alloc]initWithFrame:CGRectMake(100, 100, 414-100-10, 50)];
view.backgroundColor = [UIColor redColor];
//视图添加方法
[self.view addSubview:view]; //index 0 红色
UIView *view2 = [[UIView alloc]initWithFrame:CGRectMake(110, 110, 414-100-10, 50)];
view2.backgroundColor = [UIColor greenColor];
//把某个视图插入到某个位置
[self.view addSubview:view2];// index 1 绿色
UIView *view3 = [[UIView alloc]initWithFrame:CGRectMake(120, 120, 414-100-10, 50)];
view3.backgroundColor = [UIColor blueColor];
//把某个视图插入到某个位置
[self.view addSubview:view3];//index 2 蓝色
//bringSubviewToFront 吧某个view移动到最前面
[self.view bringSubviewToFront:view];//把红色的视图移到最前面
//sendSubviewToBack 吧某个view发送到最下方
[self.view sendSubviewToBack:view3];
}
@end
//xr 414*896