原文地址::https://blog.csdn.net/sanglong117/article/details/45826785
相关文章
1、UIViewController的几种跳转模式及其应用----https://blog.csdn.net/loongwong2011/article/details/52203154
2、iOS中UIView之间布局及跳转的几种方式----https://www.2cto.com/kf/201506/408674.html
3、UIViewController之间的相互跳转----https://www.cnblogs.com/worldtraveler/p/4570842.html
4、iOS中UIView之间布局及跳转的几种方式----https://www.jianshu.com/p/50ae0ccd350e
5、UIView页面 与UIViewController之间的跳转----https://www.jianshu.com/p/e6b493ff0d95
6、ios 怎么从一个uiview 跳转到一个uiviewcontroller----https://zhidao.baidu.com/question/1732224052144099707.html
一、两个UIView之间的跳转
//在.h文件中定义全局view_1、view_2
-(void)toView1{
if(!view_2){
[view_2 removeFromSuperview];
}
view_1 = [[UIView alloc]initWithFrame:CGRectMake(0,0,320,480)];
[self.window addSubview:view_1];
UIImageView *imageView_1 = [[UIImageView alloc]initWithFrame:CGRectMake(0,0,320,480)];
imageView_1.image = [UIImage imageNamed:@"pic1"];
[view_1 addSubview:imageView_1];
UIButton *button_1 = [UIButton buttonWithType:UIButtonTypeSystem];
button_1.frame = CGRectMake(0,0,320,480);
[button_1 addTarget:self action:@selector(toView2) forControlEvents:UIControlEventTouchUpInside];
[view_1 addSubview:button_1];
}
-(void)toView2{
[view_1 removeFromSuperview];
view_2 = [[UIView alloc]initWithFrame:CGRectMake(0,0,320,480)];
[self.window addSubview:view_2];
UIImageView *imageView_2 = [[UIImageView alloc]initWithFrame:CGRectMake(0,0,320,480)];
imageView_2.image = [UIImage imageNamed:@"pic2"];
[view_2 addSubview:imageView_2];
UIButton *button_2 = [UIButton buttonWithType:UIButtonTypeSystem];
button_2.frame = CGRectMake(0,0,320,480);
[button_2 addTarget:self action:@selector(toView1) forControlEvents:UIControlEventTouchUpInside];
[view_2 addSubview:button_2];
}
二、tag作用:可以为控件定义一个值,来区分控件。
通过改变背景颜色测试tag的调用
-(void)clickButton{
UIButton *button_1 = [UIButton buttonWithType:UIButtonTypeSystem];
button_1.frame = CGRectMake(100,100,120,40);
[button_1 addTarget:self action:@selector(testTag:) forControlEvents:UIControlEventTouchUpInside];
button_1.tag = 10000;
[self.window addSubview:button_1];
UIButton *button_2 = [UIButton buttonWithType:UIButtonTypeSystem];
button_2.frame = CGRectMake(100,160,100,40);
[button_2 addTarget:self action:@selector(testTag:) forControlEvents:UIControlEventTouchUpInside];
button_2.tag = 20000;
[self.window addSubview:button_2];
}
-(void)testTag:(id)sender{
switch([sender tag]){
case 10000:
[self.window.backgroundColor [UIColor purpleColor]];
break;
case 20000:
[self.window.backgroundColor [UIColor grayColor]];
break;
default:
break;
}
}
三、UIAlertView提示框(仅显示,功能未实现)
定义提示框:
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"有提示:" message:@"输入错误,请重试" delegate:self cancelButton:@"取消" otherButton:@"第一button",@"第二button",nil];//可定义多个
[alert show];