Swift 发布构建设置的动画完成错误
Swift animation completion bug with release build settings
有两个视图控制器,Initial 和 modal。我们在初始控制器中有动画,在模态控制器中也有动画。每个动画都有完成块。我们将build scheme 运行 –> Build configuration设置为Release。 运行 应用程序,转到模态控制器和 运行 动画。在动画之后(在模态控制器中)调用 Initial 控制器中的动画完成块而不是模态控制器中的完成块。有人也遇到过吗?有什么建议吗?
Sample project here
(Product -> Scheme -> Edit scheme -> 运行 -> Build configuration: Release)
这绝对是一个优化错误。
我发现的一个快速解决方法是将 completions:
闭包转换为 @objc_block
。
ViewController:
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
// ^^^^^^^^^^^^^^^^^^^^^^^^^^
)
ViewController2:
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
// ^^^^^^^^^^^^^^^^^^^^^^^^^^
)
有两个视图控制器,Initial 和 modal。我们在初始控制器中有动画,在模态控制器中也有动画。每个动画都有完成块。我们将build scheme 运行 –> Build configuration设置为Release。 运行 应用程序,转到模态控制器和 运行 动画。在动画之后(在模态控制器中)调用 Initial 控制器中的动画完成块而不是模态控制器中的完成块。有人也遇到过吗?有什么建议吗?
Sample project here (Product -> Scheme -> Edit scheme -> 运行 -> Build configuration: Release)
这绝对是一个优化错误。
我发现的一个快速解决方法是将 completions:
闭包转换为 @objc_block
。
ViewController:
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
// ^^^^^^^^^^^^^^^^^^^^^^^^^^
)
ViewController2:
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
// ^^^^^^^^^^^^^^^^^^^^^^^^^^
)