美文网首页
iOS-当前VC上present一个半透明的ViewContro

iOS-当前VC上present一个半透明的ViewContro

作者: fly大梦想家 | 来源:发表于2018-06-12 14:21 被阅读231次

    1.弹出控制器

      GOVAlertViewController *alertVC = [[GOVAlertViewController alloc] init];
      alertVC.modalPresentationStyle = UIModalPresentationOverFullScreen;
       [self presentViewController:alertVC animated:NO completion:nil ];
    

    因为父视图的透明度会影响到子视图,所以想要在GOVAlertViewController上添加各种view的话,先给GOVAlertViewController添加一个全屏的半透明背景view ; 或者简单的给父视图背景色[UIColor colorWithRed:0 green:0 blue:0 alpha:0.6];里设置透明度

    - (id)init{
        if (self == [super init]) {
            self.view.backgroundColor = [UIColor clearColor];
            UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
            bgView.backgroundColor = [UIColor blackColor];
            bgView.alpha = 0.6;
            [self.view addSubview:bgView];
            
            UIImageView *alertView = [[UIImageView alloc] initWithFrame:CGRectMake((self.view.frame.size.width - 300)/ 2.0, (self.view.frame.size.height - 500)/ 2.0, 300, 500)];
            alertView.alpha = 1;
            alertView.image = [UIImage imageNamed:@"alert.jpeg"];
            alertView.contentMode = UIViewContentModeScaleAspectFit;
            [self.view addSubview:alertView];
        }
        return self;
    }
    
    2501528783957_.pic.jpg

    相关文章

      网友评论

          本文标题:iOS-当前VC上present一个半透明的ViewContro

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