2017-02-09 137 views
1

我可以讓我的按鈕隱藏,但不隱藏按鈕不會取消隱藏

隱藏用自來水的answerOneCover按鈕:

@IBAction func answerOneCoverTapped(_ sender: Any) { 
    animateButtonCoverOut(button: answerOneCover) 
} 

func animateButtonCoverOut(button: UIButton) { 

    UIView.animate(withDuration: 1.0, delay: 0.1, options: 
     UIViewAnimationOptions.curveEaseOut, animations: { 
      button.alpha = 0 
    }, completion: { finished in 
     button.isHidden = true 
    }) 
} 

我嘗試取消隱藏answerOneCover按鈕時不同的按鈕,answerOneButtonText按鈕被竊聽

@IBAction func answerOneButtonTextTapped(_ sender: Any) { 
    answerOneCover.isHidden = false 
} 

但我無法取得answerOneCover的取消隱藏。有沒有辦法做到這一點,我錯過了?

回答

3

你必須設置按鈕阿爾法回到。改變你的代碼看起來像這樣:

@IBAction func answerOneButtonTextTapped(_ sender: Any) { 
    answerOneCover.alpha = 1 
    answerOneCover.isHidden = false 
} 

OR,你可以把它放在你的動畫完成,像這樣:

func animateButtonCoverOut(button: UIButton) { 

    UIView.animate(withDuration: 1.0, delay: 0.1, options: 
     UIViewAnimationOptions.curveEaseOut, animations: { 
      button.alpha = 0 
    }, completion: { finished in 
     button.isHidden = true 
     button.alpha = 1 
    }) 
} 
+2

另一種選擇是從來沒有使用'isHidden'。只需根據需要設置「alpha」即可。 – rmaddy

+0

@rmaddy感謝您的提示! – SRMR

+1

@kenny謝謝你的回答,完美! – SRMR