iOS开发17-iOS 模态视图的使用
2015-11-04 22:40
561 查看
iOS开发17-iOS 模态视图的使用
代码下载(Xcode7.0.1)有问题请联系博主,邮箱:nathanlee1987@aliyun.com
模态视图控制器并不是一个类,只是一种方式显示的controller。
在程序中切换页面可以使用UINavigationController,也可以使用模态视图。
IOS下的视图控制器都会有一个presentViewController方法,用来显示模态窗口,在一些特别的环境下我们尤其愿意使用这种窗口,例如临时呈现一些内容时(登录视图、分享列表视图等),所以今天在这里做一下整理。
代码:
-(void)buttonAction:(UIButton*)sender{ NextViewController *nextVC = [[NextViewController alloc]init]; nextVC.modalPresentationStyle=UIModalPresentationFormSheet; nextVC.modalTransitionStyle=UIModalTransitionStyleCoverVertical; /* 弹出View Controller时的风格 UIModalPresentationFullScreen UIModalPresentationPageSheet UIModalPresentationFormSheet UIModalPresentationCurrentContext UIModalPresentationCustom UIModalPresentationOverFullScreen UIModalPresentationOverCurrentContext UIModalPresentationPopover UIModalPresentationNone */ /*modalTransitionStyle场景切换动画的风格 UIModalTransitionStyleCoverVertical UIModalTransitionStyleFlipHorizontal UIModalTransitionStyleCrossDissolve UIModalTransitionStylePartialCurl */ [self presentModalViewController:nextVC animated:YES]; [self presentViewController:nextVC animated:YES completion:nil]; } -(void)p_setupViews{ self.view.backgroundColor = [UIColor grayColor]; UIButton *button1 =[UIButton buttonWithType:UIButtonTypeCustom]; button1.frame = CGRectMake(100, 100, 150, 30); [button1 setTitle:@"显示模态视图" forState:UIControlStateNormal]; button1.backgroundColor=[UIColor orangeColor]; [self.view addSubview:button1]; [button1 addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside]; } - (instancetype)init { self = [super init]; if (self) { [self p_setupViews]; } return self; } - (void)viewDidLoad { [super viewDidLoad]; }
返回代码:
-(void)buttonAction:(UIButton*)sender{ [self dismissViewControllerAnimated:YES completion:nil]; } -(void)p_setupViews{ self.view.backgroundColor = [UIColor redColor]; UIButton *button1 =[UIButton buttonWithType:UIButtonTypeCustom]; button1.frame = CGRectMake(100, 100, 80, 30); [button1 setTitle:@"返回" forState:UIControlStateNormal]; button1.backgroundColor=[UIColor blueColor]; [self.view addSubview:button1]; [button1 addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside]; } - (instancetype)init { self = [super init]; if (self) { [self p_setupViews]; } return self; } - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. }
效果:
代码下载(Xcode7.0.1)
有问题请联系博主,邮箱:nathanlee1987@aliyun.com
著作权声明:本文由http://my.csdn.net/Nathan1987_原创,欢迎转载分享。请尊重作者劳动,转载时保留该声明和作者博客链接,谢谢
相关文章推荐
- iOS开发16-iOS NSTimer的使用
- iOS常遇到的錯誤訊息與解決方式
- IOS之atomicnonatomic,assign,copy與retain的定義和區別
- 小议iOS------block传值 回调传值
- iOS与内存管理
- iOS 常用的第三方类库
- iOS开发见闻-第5期
- iOS 本地图片与视频
- iOS回收键盘小见
- iOS开发-常用第三方开源框架介绍(你了解的ios只是冰山一角)
- iOS Property List and Views学习笔记(Lesson 5)
- iOS 画板的简单实现
- iOS关于CGContextSetBlendMode: invalid context 0x0的错误
- iOS 明明存在的头文件,导入时却提示找不到。
- iOS第三方框架---SDWebImage详解
- iOS得知1_初体验
- iOS录音功能真机调试失败
- IOS 时区问题
- 串口Termios
- 蓝懿ios 技术内容和心得交流分享 11.4 控件