2017-03-08 87 views
0

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

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

这可能吗?

在我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]]; 
} 

感谢

回答

0

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

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