2017-03-07 118 views
0

下午好,UITapGestureRecognizer not working on UIView animated

我嘗試在UIView上實現UITapGestureRecognizer。

我創建了UITapGestureRecognizer並像這樣分配給我的UIView。

let gestureGeneral = UITapGestureRecognizer(target: self, action: #selector (self.toConfigurationGeneral(_:))) 
self.mode_view.addGestureRecognizer(gestureGeneral) 

這是我的方法toConfigurationGeneral:

func toConfigurationGeneral(_ sender:UITapGestureRecognizer){ 
    let nextViewController = storyBoard.instantiateViewController(withIdentifier: "ConfigurationGeneralViewController") as! ConfigurationGeneralViewController 
    self.navigationController?.pushViewController(nextViewController, animated: false) 
} 

此代碼是偉大的工作,但是當我在這的UIView添加動畫,我的方法是不叫。這是我的動畫:

UIView.animate(withDuration: 0.5, delay: 0, options: [.curveEaseIn, .repeat, .autoreverse, .allowUserInteraction, .allowAnimatedContent], animations: { 
     self.mode_view.alpha = 0 
} , completion: nil) 

謝謝你的回答。

回答

0

當您的視圖的alpha設置爲0時,所有GestureRecognizer都無法使用。

你可以添加一個新的子視圖與你mode_view和相同mode_view的同一幀清晰的背景顏色。 並添加到它GestureRecognizer。 當您的mode_view將被隱藏時,新子視圖將調用該方法。

你也可以只添加這個清晰轉到後臺

0

當你要使用GestureRecognizer需要userInteractionEnabled設置爲true視圖 請確認您 mode_view.userInteractionEnabled =真

新的子視圖手勢