zoukankan      html  css  js  c++  java
  • iOS模态弹出半透明视图控制器

    项目中需要实现点击按钮出现的视图全屏覆盖,呈半透明状态可以看到下面的视图?

    解决方案:

    绕了很多弯路原来可以使用模态弹出一个视图控制器

    在iOS8之后只需要设置一个最新的属性

    SecondViewController *vc=[[SecondViewController alloc]init];
        vc.modalPresentationStyle = UIModalPresentationOverCurrentContext;
        [self presentViewController:vc animated:NO completion:^{
    //        vc.view.backgroundColor=[UIColor colorWithRed:0 green:0 blue:0 alpha:0.8];
            vc.view.backgroundColor = [UIColor orangeColor];
            vc.view.alpha = 0.5;
        }];

    在iOS7或更低需要设置你的window.rootViewController.modalPresentationStyle = UIModalPresentationCurrentContext

    AppDelegate *appdelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
        UIViewController *vc=[[UIViewController alloc]init];
        appdelegate.window.rootViewController.modalPresentationStyle=UIModalPresentationCurrentContext;
        [appdelegate.window.rootViewController presentViewController:vc animated:YES completion:^{
            vc.view.backgroundColor=[UIColor colorWithRed:0 green:0 blue:0 alpha:0.8];
            appdelegate.window.rootViewController.modalPresentationStyle=UIModalPresentUIModalPresentationFullScreen;
        }];

     实现完成后发现了一个bug, 如果当presentingVC有根视图控制器tabBarController,上面的设置会使tabBar未被覆盖,意思就好像是你有一直看到presentingVC直接导致不会走viewWiillAppear,不能在原视图即将出现时把隐藏tabBar的属性改回来。此时

    在present的时候敲一行

        self.tabBarController.tabBar.hidden = YES; // 隐藏tabBar

    在dismiss的时候敲一行

        self.presentingViewController.tabBarController.tabBar.hidden = NO; // 先获取弹出视图的视图控制器,再修改隐藏属性
  • 相关阅读:
    自己实现的string的库函数
    单链表的面试题
    顺序表的实现
    指针数组与数组指针
    指针与数组
    sizeof 与 strlen
    HTML配色工具!在线配色工具
    [转载] python的sorted函数对字典按key排序和按value排序
    [转载]python脚本删除一定时间以外的文件
    python基础教程(四)
  • 原文地址:https://www.cnblogs.com/xs514521/p/5643835.html
Copyright © 2011-2022 走看看