2016-08-30 71 views
2

很簡單的情況。我有一個自定義的UIViewController來填充表單。當用戶點擊取消按鈕時,我想要彈出提醒; 「你確定要退出表單嗎?你的編輯不會被保存」。如果他們擊中了,VC會做動畫然後關閉。的iOS UIAlertController中斷動畫

我將動畫放置在UIAlertAction處理程序閉包中。但是,動畫每次都會立即發生,我假設這是因爲UIAlertController在解除按鈕(按下按鈕後)時產生動畫,然後中斷VC的動畫。

任何想法?基本上看起來,只要按下按鈕,處理程序就會被調用;如何在UIAlertController完成解除後調用處理程序。

編輯:下面是一些示例代碼來說明這個問題:

let refreshAlert = UIAlertController(title: "Delete draft?", message: "Are you sure you want to discard this draft? It will not be saved.", preferredStyle: UIAlertControllerStyle.Alert) 

refreshAlert.addAction(UIAlertAction(title: "Delete", style: .Destructive, handler: { (action: UIAlertAction!) in 
    self.animationInPresentionVC() // This animation occurs instantly, it seems to be interrupted by the dismissing alert controller 
})) 

回答

2

也許你可以添加一些延遲執行您的animationInPresentionVC():

refreshAlert.addAction(UIAlertAction(title: "Delete", style: .Destructive, handler: { (action: UIAlertAction!) in 
    self.performSelector(#selector(**your animationInPresentionVC**), , withObject: nil, afterDelay:0.3) 
})) 
+0

沒錯,這就是我結束了做,工作很好...感覺像有點黑客雖然:(謝謝! – Josh