2017-06-05 52 views
0

我創建blurEffectView這樣:從上海華卸下與gestureRecognizer

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

它可能被MapView的手勢識別器覆蓋。嘗試將blurView放置在mapView上,而不是mapView的子視圖。作爲父視圖的子視圖。 – JustinM

+0

這沒有奏效,而且我還是需要它作爲mapView的超級視圖,因爲在模糊效果視圖的頂部有另一個視圖,它是不應該模糊的父視圖的子視圖。 – Latcie

+0

只是使用bringtofront到你的blurview –

回答

0

試試這個

class YourViewController: UIViewController, UIGestureRecognizerDelegate{ 

    tapGestureRecognizer.delegate = self 

    func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool { 
      return true 
    } 
} 
0

嘗試,因爲它的工作對我來說,使用此代碼。我已經更改了塊聲明,並在viewDidLoad中設置了塊的外部大小。

var blurEffectView: UIVisualEffectView = { 
     let blurEffect = UIBlurEffect(style: UIBlurEffectStyle.light) 
     let blurEffectView = UIVisualEffectView(effect: blurEffect) 
     blurEffectView.autoresizingMask = [.flexibleWidth, .flexibleHeight] 
     return blurEffectView 
    }() 

//設置UIVisualEffectView框架viewDidLoad中

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() 
    } 
+0

雖然這段代碼可能回答這個問題,但提供關於如何和/或爲什麼它解決問題的附加上下文會提高答案的長期價值。 – thewaywewere

+0

@thewaywewere感謝您的建議,我一定會照顧它的。 –