【发布时间】:2016-09-22 11:03:20
【问题描述】:
我想在用户点击后退按钮以继续返回我的根视图控制器时执行动画。动画只会突出显示用户在详细视图控制器中所做的更改。
我试过这个。动画本身是有效的(对我的问题并不是很重要,只是为了说明我在做什么。)问题是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)
})
}
}
【问题讨论】:
-
我认为 viewWillDisappear 不适合做这件事。我认为您应该考虑为动画构建另一个功能,并在需要时继续...(动画完成后)
-
@William GP 但我希望动画在用户重新回到根视图控制器时发生。那么,我该怎么做呢?
-
你的segue目前在哪里?它是如何触发的?
-
@William GP 通过按左上角的后退按钮,我正在从我的详细视图控制器返回到我的根视图控制器。
-
使用故事板?我会将上面的代码放入该返回按钮的函数中,然后在动画完成后将
prepareForSegue放在函数的末尾
标签: ios swift animation wait viewwilldisappear