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

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

 代码下载(Xcode7.0.1)



模态视图控制器并不是一个类,只是一种方式显示的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.
}



效果:



  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值