我有一个弹出 View 向用户显示一些信息,当前 View 的框架是一个黑色的半透明框。我想对此框应用一些模糊,以提高呈现给用户的内容的清晰度。
我有这个代码:
已更新
class PinDetails : UIView {
var popupView:UIView!
var txtName:UITextField!
var img1:UIButton!
var img2:UIButton!
var img3:UIButton!
var selectedIndex:Int!
var dictLocation:[String:String]!
var blur:UIBlurEffect = UIBlurEffect(style: UIBlurEffectStyle.Light)
override init(frame: CGRect) {
super.init(frame: frame)
var effectView:UIVisualEffectView = UIVisualEffectView (effect: blur)
effectView.frame = frame
addSubview(effectView)
popupView = UIView(frame:TCRectMake(x: 25,y: 120,width: 270,height: 285))
popupView.layer.cornerRadius = 20
popupView.backgroundColor = UIColor(white:0, alpha: 0.5)
self.addSubview(popupView)
我尝试实现的模糊代码似乎不起作用,xcode 指出:
实例成员“blur”不能用于“PinDetails”类型
。
感谢任何帮助,我对 Swift 还很陌生:)
最佳答案
尝试放置您的
var effectView:UIVisualEffectView = UIVisualEffectView (effect: blur)
effectView.frame = frame
addSubview(effectView)
在 init() 内部。您正在使用尚未初始化的属性。
-- 更新 --
我建议使用您创建的 Popupview 框架来创建视觉效果 View 。在你的 init() 中尝试一下
// Create the popup view
popupView = UIView(frame:CGRectMake(25,120,270,285))
popupView.layer.cornerRadius = 20
popupView.backgroundColor = UIColor(white:0, alpha: 0.5)
// Create the Effect View and apply to Popup view
let effect = UIVisualEffectView(frame: CGRectMake(0,0,popupView.layer.frame.width, popupView.layer.frame.height))
effect.effect = blur
popupView.addSubview(effect)
// Add the popupview to the main view
self.addSubview(popupView)
关于swift - 将模糊应用于透明弹出 View ,快速,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38164516/