ios - 带有发布build设置的 Swift 动画完成错误

标签 ios iphone swift ios8

有两个 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/

相关文章:

ios - 如何将 Mapkit 限制在某些缩放级别?

ios - 更改选项卡栏外观

iphone - 核心数据保存UIImage

swift - 游戏中一个 ViewController 的多个场景

objective-c - 使用 NSNumberFormatter numberFromString 的精度错误

ios - OAuth 2嵌入式浏览器将被阻止

iphone - 远程重新加载 View

ios - 为什么我的 UIButton 图像大小在模拟器和设备中不同?

Swift 使用 Alamofire 发出 http 请求

ios - 符合 Swift 中的 UITableViewDelegate 和 UITableViewDatasource 吗?