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; // 先获取弹出视图的视图控制器,再修改隐藏属性
  • 相关阅读:
    vim的modeline
    python的read() 、readline()、readlines()、xreadlines()
    hashset
    java泛型
    eclipse常用快捷键
    互联网计费模式
    cocos2d::CCFileUtils::sharedFileUtils()->getFileData(szFile, "r", &bufferSize) 不同平台返回值不一样
    CSS为英文和中文字体分别设置不同的字体
    fatal error C1010: 在查找预编译头时遇到意外的文件结尾
    JavaScript权威指南第03章 类型、值和变量(1)
  • 原文地址:https://www.cnblogs.com/xs514521/p/5643835.html
Copyright © 2011-2022 走看看