2016-11-17 28 views
-1

我試圖動畫是否隱藏,似乎工作確定,但如果我錯誤地設置yes到真正的5倍動畫是否隱藏=假 5次,然後有時候我應該動畫是否隱藏= true 2或更多時間讓我的UIView可見!UIView.animate不是動畫布爾值完全

我錯過了什麼嗎?

if (yes) 
{ 
    UIView.animate(withDuration: 0.3, delay:0, animations: { 
       myLabel.isHidden=false 
      } 
} 
else 
{ 
    UIView.animate(withDuration: 0.3, delay:0, animations: { 
       myLabel.isHidden=true 
      } 
} 

回答

1

您不應該爲視圖的「isHidden」參數設置動畫。你應該動畫它的alpha。

if (yes) 
{ 
    UIView.animate(withDuration: 0.3, delay:0, animations: { 
       myLabel.alpha=1.0 
      } 
} 
else 
{ 
    UIView.animate(withDuration: 0.3, delay:0, animations: { 
       myLabel.alpha=0.0 
      } 
} 

- 更新 -

如果你想隱藏就可以使用這個動畫後認爲:

myLabel.isHidden=false 
UIView.animateWithDuration(0.3, delay: 0.0, options: .CurveEaseOut, animations: { 
    myLabel.alpha=1.0 
    }, completion: { finished in 

    }) 

UIView.animateWithDuration(0.3, delay: 0.0, options: .CurveEaseOut, animations: { 
    myLabel.alpha=0.0 
    }, completion: { finished in 
    myLabel.isHidden=true 
    }) 
+0

但我需要,所以它從視圖中刪除後自動版式縮小布局動畫是否隱藏。 – AVEbrahimi

+0

@Avebrahimi請檢查我更新的答案。 –

0

我認爲問題是,你是在用線性動畫Bool類型只有2個值(false = 0,true = 1)以及其間的任何其他值(它是脈衝)。

試試這個:

if (yes) 
{ 
    myLabel.alpha = 0 
    myLabel.isHidden = false 
    UIView.animate(withDuration: 0.3, animations: { 
       myLabel.alpha = 1 
      }) 
} 
else 
{ 
    UIView.animate(withDuration: 0.3, animations: { 
       myLabel.alpha = 0 
      }, completion: { (status) in 
       myLabel.isHidden = true 
      }) 
} 
+0

但我需要動畫isHidden,所以從視圖中刪除後,自動佈局會縮小布局。 – AVEbrahimi

+0

所以試着用'UILabel'框架的alpha屬性來設置動畫效果。 – maho125