UIVisualEffects,UIWebView透明背景

时间:2017-03-08 12:11:44

标签: ios cordova uiwebview uivisualeffectview

我正在使用Cordova构建iOS应用。 我希望我的webview是透明的,并在其背后模糊用户壁纸的背景。像ios提醒应用程序一样。

我知道这是一个常见问题,但我没有找到指定回复

有可能吗?

在我的viewDidLoad方法中,我添加了以下几行:

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.view.backgroundColor = [UIColor clearColor];

    UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
    UIVisualEffectView *blurEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
    blurEffectView.frame = self.view.bounds;
    blurEffectView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

    //This line places a dark black background with my app being blurred behind it
    [self.view addSubview:blurEffectView];

    //This line instead just makes background of app plain black (the body of html app is transparent)  and not blurred , I guess there is something wrong with view hierarchy maybe? 
    [self.view addSubview:self.webView];


    [self.webView setOpaque:NO];
    [self.webView setBackgroundColor:[UIColor clearColor]];
}

提前致谢

1 个答案:

答案 0 :(得分:0)

设置webview背景颜色和不透明度的顺序应该是这样的

[self.webView setBackgroundColor:[UIColor clearColor]];
[self.webView setOpaque:NO];