有两个 View Controller ,Initial 和 modal。我们在初始 Controller 中有动画,在模态 Controller 中也有动画。每个动画都有完成 block 。我们设置build scheme Run –> Build configuration为Release。运行应用程序,转到模态 Controller 并运行动画。在动画之后(在模态 Controller 中)调用 Initial Controller 中的动画完成 block 而不是模态 Controller 中的完成 block 。有人也遇到过吗?有什么建议吗?
Sample project here (Product -> Scheme -> Edit scheme -> Run -> Build configuration: Release)
最佳答案
这绝对是一个优化错误。
我发现的一个快速解决方法是将 completions:
闭包转换为 @objc_block
。
View Controller :
UIView.animateWithDuration(0.3,
delay: 0.0,
options: UIViewAnimationOptions.CurveEaseInOut,
animations: { () -> Void in
self.rectangleView.alpha = 1.0
},
completion: { (complete) -> Void in
println("111 Hello ViewController 1")
} as @objc_block (Bool) -> Void
// ^^^^^^^^^^^^^^^^^^^^^^^^^^
)
View Controller 2:
UIView.animateKeyframesWithDuration(duration,
delay: 0.0,
options: UIViewKeyframeAnimationOptions.CalculationModeLinear,
animations: { () -> Void in
UIView.addKeyframeWithRelativeStartTime( 0.0,
relativeDuration: (duration / 2),
animations: { () -> Void in
self.rectangleView.alpha = 0.1
}
)
UIView.addKeyframeWithRelativeStartTime(
(duration / 2),
relativeDuration: (duration / 2),
animations: { () -> Void in
self.rectangleView.backgroundColor = UIColor.blueColor()
}
)
},
completion: { (complete) -> Void in
println("Hello ViewController 2")
} as @objc_block (Bool) -> Void
// ^^^^^^^^^^^^^^^^^^^^^^^^^^
)
关于ios - 带有发布build设置的 Swift 动画完成错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28236360/