从swift 1.2迁移到swift 2后出错

时间:2016-02-23 10:14:40

标签: ios swift

UIView.animateWithDuration(0.2, animations: { () -> Void in

            self.layoutIfNeeded()

            }) { (finished) -> Void in
    .......
    .......
    }

此代码抛出此错误: 无法转换类型'(_)throws - >的值Void'到预期的参数类型'((Bool) - > Void)?'

3 个答案:

答案 0 :(得分:0)

您似乎没有正确关闭括号并错过了完成参数。 检测此类错误的最简单方法是尝试重写该方法。 试试这个:

UIView.animateWithDuration(0.2, animations: { () -> Void in
        self.layoutIfNeeded()
        }, completion: { (finished) -> Void in
            ///
    })

答案 1 :(得分:0)

写下面的代码,这将工作bcz它在我身边工作,

 UIView.animateWithDuration(0.2, animations: { () -> Void in

        //your code here
        self.layoutIfNeeded()

        }) { (flag : Bool) -> Void in

            ///
    }

答案 2 :(得分:0)

这是生成相同xcode的代码,试试这个。

UIView.animateWithDuration(0.2, animations: { 
    // Code for animation

}) { (finished: Bool) in
    // Code for completion
}
相关问题