美文网首页
iOS模态出半透明的视图

iOS模态出半透明的视图

作者: 跃文 | 来源:发表于2019-03-18 10:33 被阅读0次

    模态出一个半透明的视图,在目标视图中设置背景颜色然后发现模态动作结束后变成了黑色或者不是半透明的颜色。

    解决方案:

    - (void)presentViewController {
    
        MyAlertController * alertVC = [MyAlertController new];
    
        alertVC.definesPresentationContext = YES; //self is presenting view controller
        alertVC.view.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:.4];
        alertVC.modalPresentationStyle = UIModalPresentationOverCurrentContext;
    
        [self presentViewController:testVC animated:YES completion:nil];
    }
    

    注意:如果present 一个UINavigationController,不能完全使用上面代码。

    - (void)presentNavigationController {
    
        MyAlertController * alertVC = [MyAlertController new];
        alertVC.definesPresentationContext = YES; //self is presenting view controller
        alertVC.view.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:.5];
    //    alertVC.modalPresentationStyle = UIModalPresentationOverCurrentContext;
        UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController: alertVC];
        nav.modalPresentationStyle = UIModalPresentationOverCurrentContext;
        nav.view.backgroundColor = [UIColor clearColor];
    
        [self presentViewController:nav animated:YES completion:nil];
    }
    

    相关文章

      网友评论

          本文标题:iOS模态出半透明的视图

          本文链接:https://www.haomeiwen.com/subject/sgzmmqtx.html