2017-04-27 41 views
0

我設置了一個非常類似於YouTube的界面,如果用戶按下UIView,我將使用動畫隱藏或顯示所有子視圖。更改UIButton alpha然後無法識別水龍頭

func setupControlViewVisiblity(playingVideo: Bool = false, duration: TimeInterval = 1.0, isExpanded: Bool = false){ 
     var alpha:CGFloat = 1 

    if isShowingControls { 
     //If we're showing then we're about to hide everything so alpha is 0 
     alpha = 0 
    } 


    UIView.animate(withDuration: duration, delay: 0, usingSpringWithDamping: 1, initialSpringVelocity: 1, options: .curveEaseOut, animations: { 

     self.pausePlayButton.alpha = alpha 
     self.backButton.alpha = alpha 
     self.infoLabel.alpha = alpha 
     self.fullScreenButton.alpha = alpha 
     self.currentTimeLabel.alpha = alpha 
     self.videoLengthLabel.alpha = alpha 
     self.videoSlider.alpha = alpha 

    }, completion:nil) 

    isShowingControls = !isShowingControls 
} 

是我遇到的問題是,如果我把這種方法,我顯示控件(isShowingControls是真實的),我UIButtons不會承認第一個水龍頭。這實際上只發生在視圖alpha從0變爲1時,然後我嘗試點擊一個按鈕。

我試圖做主隊列上的動畫...不起作用。如果我將alpha從0更改爲1 ....等待幾秒鐘...然後點擊按鈕..它工作。如何在UIButtons alpha更改後立即工作?

感謝

編輯:我想它與動畫持續時間這樣做,因爲當我切換它下降到0.2它的工作原理。我怎樣才能保持它高一點,讓這個工作?

回答

0

默認情況下,UIVIew動畫不允許用戶在動畫製作動畫時進行交互。

幸運的是有一個動畫選項allowUserInteraction。沒有更多的信息,但你可以在文檔here中看到它。還值得看看所有的選項here

試試這個:

UIView.animate(withDuration: duration, delay: 0, usingSpringWithDamping: 1, initialSpringVelocity: 1, options: [.curveEaseOut, .allowUserInteraction], animations: { 

    // Update the views 

}, completion:nil) 
相關問題