2014-09-02 27 views
9

我期待在這個UIView的動畫完成關閉斯威夫特的UIView animateWithDuration完成關閉,但它似乎立即開火...稱爲立即

UIView.animateWithDuration(
     Double(0.2), 
     animations: { 
      self.frame = CGRectMake(0, -self.bounds.height, self.bounds.width, self.bounds.height) 
     }, 
     completion: { finished in 
      if(finished) { 
       self.removeFromSuperview() 
      } 
     } 
    ) 

任何人都經歷這個?我讀過其他使用中心而不是框架移動視圖有更多的成功,然而我不得不用這種方法也同樣的問題。

+0

你在哪裏執行該代碼? – akashivskyy 2014-09-02 15:16:03

+3

確保幀* *實際變化,因爲完成塊時,立即有沒有動畫調用。 – akashivskyy 2014-09-02 15:20:00

+0

在自定義的UIView類中。我動畫視圖入到位時的抽頭的任何位置發生在的init(),則上面的代碼被稱爲開始。這個框架肯定也在變化...... – 2014-09-02 15:21:10

回答

0

我最終解決了這個由hitTest()進入touchesBegan()UIView

8

移動動畫別人是有這個問題,如果有什麼遮住動畫,完成閉合立即調用。在我的情況下,這是由於與所述視圖控制器的自定義SEGUE是從退繞的模態轉換的輕微重疊。使用UIView.animateWithDuration(0.3, delay: 0, options: UIViewAnimationOptions.CurveEaseInOut, animations:{}delay部分對我有沒有效果。我最終使用GCD延遲動畫幾分之一秒。

// To avoid overlapping with the modal transiton 
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, Int64(0.2 * Double(NSEC_PER_SEC))), dispatch_get_main_queue(), { 

    // Animate the transition 
    UIView.animateWithDuration(0.3, delay: 0, options: UIViewAnimationOptions.CurveEaseInOut, animations: { 

     // Animations 

     }, completion: { finished in 

     // remove the views 
     if finished {    
      blurView.removeFromSuperview() 
      snapshot.removeFromSuperview() 
     } 
    }) 
})