iOS开发17-iOS 模态视图的使用

来源:互联网 发布:跨境电商平台数据分析 编辑:程序博客网 时间:2024/04/29 18:39

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_原创,欢迎转载分享。请尊重作者劳动,转载时保留该声明和作者博客链接,谢谢



1 0
原创粉丝点击