【问题标题】:UIVisualEffects, UIWebView transparent backgroundUIVisualEffects、UIWebView 透明背景
【发布时间】:2017-03-08 12:11:43
【问题描述】:

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

提前致谢

【问题讨论】:

    标签: ios cordova uiwebview uivisualeffectview


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2014-11-08
      • 2012-02-01
      • 2014-09-21
      • 1970-01-01
      • 2012-01-29
      • 2011-03-08
      • 1970-01-01
      • 2021-09-20
      • 2019-02-07
      相关资源
      最近更新 更多