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

2018-06-12  本文已影响231人  fly大梦想家

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
上一篇下一篇

猜你喜欢

热点阅读