2017-10-08 9 views
0

私は、制約にアニメーションを適用して、ビューにlogoImageを持っています。 アニメーション化された制約は、幅と高さです。 220.0の元の状態から240.0になり(うまくいきます)、220.0に戻したいのですが、アニメーションはスキップされ、画像は0.1秒から220.0に直接戻ります。ここでスウィフトは1つのアニメーションをスキップします(UIView.animate)

は、アニメーションのコードは、私が得ることができるすべての助けを事前に

func animate() { 

     self.imageHeightConstraint.constant = 240.0 
     self.imageWidthConstraint.constant = 240.0 

     UIView.animate(withDuration: 1.0, 
         delay:0.0, 
         options: .curveEaseIn, 
         animations:{ 

         self.logoImage.layoutIfNeeded() 

     }, completion: { (finished: Bool) -> Void in 

      self.imageHeightConstraint.constant = 220.0 
      self.imageWidthConstraint.constant = 220.0 



      UIView.animate(withDuration: 2.0, 
          delay:0.0, 
          options: .curveEaseIn, 
          animations: { 

       self.logoImage.layoutIfNeeded() 

      }) 

     }) 

    } 

感謝です! ;-)

答えて

1

定数を再設定する前に、完了ブロック内でself.logoImage.setNeedsLayout()に電話する必要があります。これは、レシーバの現在のレイアウトを無効にして、次のアップデートサイクル中にレイアウトの更新をトリガする必要があるためです。

代わりにこのコードを試してみて、それがあなたのために動作します:

勤務
func animate() { 
    self.imageHeightConstraint.constant = 240.0 
    self.imageWidthConstraint.constant = 240.0 
    UIView.animate(withDuration: 1.0, 
        delay:0.0, 
        options: .curveEaseIn, 
        animations:{ 

        self.logoImage.layoutIfNeeded() 

    }, completion: { (finished: Bool) -> Void in 
     self.logoImage.setNeedsLayout() 
     self.imageHeightConstraint.constant = 220.0 
     self.imageWidthConstraint.constant = 220.0 

     UIView.animate(withDuration: 2.0, 
         delay:0.0, 
         options: .curveEaseIn, 
         animations: { 

      self.logoImage.layoutIfNeeded() 

     }) 
    }) 
} 
+0

!どうもありがとうございます ;) – Julien

関連する問題