我创建了一个blurEffectView:
var blurEffectView: UIVisualEffectView{
let blurEffect = UIBlurEffect(style: UIBlurEffectStyle.light)
let blurEffectView = UIVisualEffectView(effect: blurEffect)
blurEffectView.frame = self.view.bounds
blurEffectView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
return blurEffectView
}
然后使用tapGestureRecognizer添加到效果视图。
let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(self.dismissBlurView))
self.blurEffectView.addGestureRecognizer(tapGestureRecognizer)
self.mapView.addSubview(self.blurEffectView)
这是解雇它的功能:
func dismissBlurView(){
blurEffectView.removeFromSuperview()
}
我显然在这里遗漏了一些东西,因为当我点击模糊视图时没有调用dismissBlurView。
答案 0 :(得分:0)
试试这个
class YourViewController: UIViewController, UIGestureRecognizerDelegate{
tapGestureRecognizer.delegate = self
func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {
return true
}
}
答案 1 :(得分:0)
尝试使用此代码,因为它适合我。我已经改变了块声明并在viewDidLoad中将块大小设置在块之外。
var blurEffectView: UIVisualEffectView = {
let blurEffect = UIBlurEffect(style: UIBlurEffectStyle.light)
let blurEffectView = UIVisualEffectView(effect: blurEffect)
blurEffectView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
return blurEffectView
}()
//在viewDidLoad中设置UIVisualEffectView框架
self.blurEffectView.frame = self.view.bounds
self.blurEffectView.addGestureRecognizer(UITapGestureRecognizer.init(target: self, action: #selector(self.dismissBlurView(gesture:))))
self.view.addSubview(self.blurEffectView)
func dismissBlurView(gesture: UITapGestureRecognizer){
blurEffectView.removeFromSuperview()
}