当用户点击后退按钮以返回我的根视图控制器时,我想执行动画。动画将简单地突出显示用户在详细视图控制器中所做的更改。
我试过这个。动画本身是有效的(对我的问题并不是很重要,只是为了说明我在做什么。)问题是segueing发生得太快了,你看不到动画。
在动画完成之前,如何wait
执行 viewWillDisappear?
override func viewWillDisappear(animated: Bool) {
// ...
// Animate if text changes. reminderAfterRulesRun is a custom data structure. reminderNameTextInput is my outlet to my label
if reminderNameTextInput.text != reminderAfterRulesRun.title {
let originalreminderNameTextInputColor = self.reminderNameTextInput.textColor
// Animate the removing of "All" and replacing it with the most commonly used list.
UIView.animateWithDuration(0.3, delay: 0, options: .Autoreverse, animations: {
// Fade out
self.reminderNameTextInput.textColor = UIColor.redColor()
self.reminderNameTextInput.text = reminderAfterRulesRun.title
self.reminderNameTextInput.alpha = 0.0
}, completion: {
(finished: Bool) -> Void in
// Once the label is completely invisible, set the text and fade it back in
UIView.animateWithDuration(0.3, delay: 0, options: .Autoreverse, animations: {
// self.reminderNameTextInput.selectedSegmentIndex = self.toSegmentedControlValue(reminderAfterRulesRun.reminderNameTextInput)!
self.reminderNameTextInput.text = reminderAfterRulesRun.title
self.reminderNameTextInput.textColor = originalreminderNameTextInputColor
self.reminderNameTextInput.alpha = 1.0
}, completion: nil)
})
}
}