我在UIVisualEffectView
内有一个myView
。可以在屏幕上拖动myView
。此外,ViewController中还有一个图像和UIWebView
在图像上方一切正常但是当我将myView
拖到UIWebView
上方时,模糊效果不再起作用,myView
看起来像是浅灰色背景并且是透明的。
[来自真实iPad Air的结果,iOS 9.2.1]
这就是我创建模糊效果的方法:
let blurView = UIVisualEffectView(effect: UIBlurEffect(style: .ExtraLight))
blurView.frame.size = CGSizeMake(navView.frame.width, navView.frame.height)
blurView.layer.cornerRadius = navView.layer.cornerRadius
blurView.clipsToBounds = true
let vibrancyView = UIVisualEffectView()
vibrancyView.frame = blurView.frame
vibrancyView.effect = UIVibrancyEffect(forBlurEffect: blurView.effect as! UIBlurEffect)
vibrancyView.layer.cornerRadius = blurView.layer.cornerRadius
blurView.contentView.addSubview(vibrancyView)
vibrancyView.contentView.addSubview(left)
vibrancyView.contentView.addSubview(right)
myView.addSubview(blurView)
知道为什么会这样吗? 提前谢谢!
答案 0 :(得分:2)
添加此内容并尝试
myView.bringSubviewToFront(blurView)
或使用
blurView.superview.bringSubviewToFront(blurView)
<强>更新强>
变量创建
@IBOutlet var webview: UIWebView!
码
let blurView = UIVisualEffectView(effect: UIBlurEffect(style: .ExtraLight))
blurView.frame.size = CGSizeMake(200, 200)
blurView.layer.cornerRadius = 25
blurView.clipsToBounds = true
let vibrancyView = UIVisualEffectView()
vibrancyView.frame = blurView.frame
vibrancyView.effect = UIVibrancyEffect(forBlurEffect: blurView.effect as! UIBlurEffect)
vibrancyView.layer.cornerRadius = blurView.layer.cornerRadius
blurView.contentView.addSubview(vibrancyView)
// vibrancyView.contentView.addSubview(left)
//vibrancyView.contentView.addSubview(right)
webview.addSubview(blurView)
let myURL = NSURL(string: "http://www.swiftdeveloperblog.com");
let myURLRequest:NSURLRequest = NSURLRequest(URL: myURL!);
webview.loadRequest(myURLRequest);
我添加了Sample project
答案 1 :(得分:0)
试试这个
self.view.sendSubviewToBack(UIWebView)