iOS7、8半透明弹出框及弹出后弹出前页面消失问题

2016-11-15  本文已影响33人  HeminWon

需求:做一个自定义视图弹框,弹出框之外的背景视图为半透明
设计方案:使用模态视图弹出自定义视图
产生问题:presentViewController的透明部分 变成黑色不透明了
问题原因:UIModalPresentationCurrentContext的API在iOS8之后有所改变而且模态视图的设置对象有所改变

// 需注意设置modalPresentationStyle的对象有改变
if ([[[UIDevice currentDevice] systemVersion] floatValue]>=8.0) {
        nextVC.modalPresentationStyle=UIModalPresentationOverCurrentContext;
    }else{
        // 下面的self若弹出后背景全黑,可设为:self.view.window.rootViewController
        self.modalPresentationStyle=UIModalPresentationCurrentContext;
    }
    // 下面的self若弹出后界面消失,可设为:self.view.window.rootViewController
    [self presentViewController: nextVC animated:YES completion:nil];
上一篇 下一篇

猜你喜欢

热点阅读