iOS学习笔记-050.Modal模态

Modal模态

一、Modal介绍

  • 除了push之外,还有另外一种控制器的切换方式,那就是Modal

  • 任何控制器都能通过Modal的形式展示出来

  • Modal的默认效果:新控制器从屏幕的最底部往上钻,直到盖住之前的控制器为止

二、Modal操作

Modal的形式展示控制器
- (void)presentViewController:(UIViewController *)viewControllerToPresent animated: (BOOL)flag completion:(void (^)(void))completion

关闭当初Modal出来的控制器
- (void)dismissViewControllerAnimated: (BOOL)flag completion: (void (^)(void))completion;

三、代码

WMOneViewController.m

//
//  WMOneViewController.m
//  03_UIView40_Modal
//
//  Created by 杞文明 on 2016/04/10 11:54:06   星期日
//  Copyright © 2016年 杞文明. All rights reserved.
//

#import "WMOneViewController.h"
#import "WMTwoViewController.h"

@interface WMOneViewController ()

@end

@implementation WMOneViewController

- (void)viewDidLoad {
    [super viewDidLoad];
}


- (IBAction)jump2Two:(id)sender {
    //1.创建控制器
    WMTwoViewController * vc = [[WMTwoViewController alloc]init];

    //2.创建导航控制器
    UINavigationController *nvc = [[UINavigationController alloc]initWithRootViewController:vc];

    //3.模态方式打开控制器
    [self presentViewController:nvc animated:YES completion:^{
        NSLog(@"完全打开 第二个了");
    }];
}

@end

WMTwoViewController.m

//
//  WMTwoViewController.m
//  03_UIView40_Modal
//
//  Created by 杞文明 on 2016/04/10 11:53:50   星期日
//  Copyright © 2016年 杞文明. All rights reserved.
//

#import "WMTwoViewController.h"
#import "WMThreeViewController.h"
@interface WMTwoViewController ()

@end

@implementation WMTwoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    //返回按钮
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"返回" style:UIBarButtonItemStylePlain target:self action:@selector(closeTwo)];
}

/**
 *跳到第三个界面
 */
- (IBAction)jump2Three:(id)sender {
    //1.创建控制器
    WMThreeViewController *vc = [[WMThreeViewController alloc]init];

    //2.模态方式打开
    [self presentViewController:vc animated:YES completion:^{
         NSLog(@"完全打开 第三个了");
    }];

}

-(void)closeTwo{
    // 如果一个控制器是以模态的形式展现出来的, 可以调用该控制器以及该控制器的子控制器让让控制器消失
//    [self dismissViewControllerAnimated:YES completion:^{
//        NSLog(@"完全打开 第二个了");
//    }];

    [self.navigationController dismissViewControllerAnimated:YES completion:^{
        NSLog(@"完全打开 第二个了");
    }];
}

@end

WMThreeViewController.m

//
//  WMThreeViewController.m
//  03_UIView40_Modal
//
//  Created by 杞文明 on 2016/04/10 11:53:59   星期日
//  Copyright © 2016年 杞文明. All rights reserved.
//

#import "WMThreeViewController.h"

@interface WMThreeViewController ()

@end

@implementation WMThreeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
}

//关闭
- (IBAction)myClose:(id)sender {
    [self dismissViewControllerAnimated:YES completion:^{
        NSLog(@"已经关闭 第三个了");
    }];
}

@end

四、图示

这里写图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值