2017-04-27 72 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)