UIView
UIView的位置
- (void)viewDidLoad {
[super viewDidLoad];
//新建三个View界面(顺序是:红在底,蓝在中,黄在上)
UIView *view1 = [[UIView alloc]initWithFrame:CGRectMake(100, 100, 100, 100)];
view1.backgroundColor = [UIColor redColor];
[self.view addSubview:view1];
UIView *view2 = [[UIView alloc]initWithFrame:CGRectMake(120, 120, 100, 100)];
view2.backgroundColor = [UIColor blueColor];
[self.view addSubview:view2];
UIView *view3 = [[UIView alloc]initWithFrame:CGRectMake(140, 140, 100, 100)];
view3.backgroundColor = [UIColor yellowColor];
[self.view addSubview:view3];
//把视图放在最前面
[self.view bringSubviewToFront:view1];
//把视图放在最后面
[self.view sendSubviewToBack:view1];
//插入视图在。。。。。。之上
[self.view insertSubview:view2 aboveSubview:view3];
//插入视图在。。。。。。之下
[self.view insertSubview:view2 belowSubview:view3];
//按照位置插入视图(这三个视图最底下是2,中间是3,上面是4)
[self.view insertSubview:view1 atIndex:4];
}
UIView的移动、缩放等
- (void)viewDidLoad {
[super viewDidLoad];
//新建一个View界面
UIView *view = [[UIView alloc]initWithFrame:CGRectMake(100, 100, 100, 100)];
//这里的tag相当于一个学号(或编号),如果程序里有很多view,编号是用来区分的
view.tag = 10;
view.backgroundColor = [UIColor redColor];
[self.view addSubview:view];
//新建一个Button,控制视图旋转,缩放等
UIButton *myButton = [[UIButton alloc]initWithFrame:CGRectMake(100, 250, 100, 50)];
myButton.backgroundColor = [UIColor blueColor];
[myButton setTitle:@"点击" forState:UIControlStateNormal];
[myButton addTarget:self action:@selector(haha:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:myButton];
}
//Button方法
-(void)haha:(id)a{
//编号接受view
UIView *view = [self.view viewWithTag:10];
//view的放大缩小
view.transform = CGAffineTransformScale(view.transform, 2, 2);
//旋转,按照弧度值
view.transform = CGAffineTransformRotate(view.transform, M_1_PI);
//移动,(是移动了,不是移动到)
view.transform = CGAffineTransformTranslate(view.transform, 50, 50);
}