Swift 在使用动画块中的函数参数时无法解析 UIView.animateWithDuration 中的 CurveEaseIn
Swift cant resolve CurveEaseIn in UIView.animateWithDuration when using parameter from function inside animation block
我正在尝试将参数传递给函数以动态更改动画块中的布局约束。
这个有效:
func moveKeyboard (up: Bool, newMargin: Int)
{
UIView.animateWithDuration(0.2, delay: 0, options: .CurveEaseIn, animations: {
self.topMarginConstraint.constant=10;
}, completion: { finished in
println("Animation end!")
})
}
这不是(我收到错误 "Could not find member CurveEaseIn"):
func moveKeyboard (up: Bool, newMargin: Int)
{
UIView.animateWithDuration(0.2, delay: 0, options: .CurveEaseIn, animations: {
self.topMarginConstraint.constant=newMargin;
}, completion: { finished in
println("Animation end!")
})
}
我应该如何定义我的函数才能在动画块中使用 newMargin 参数?
这是因为,"constant" 是 "CGFLoat" 类型,而你正在传递 "Int":
func moveKeyboard (up: Bool, newMargin: CGFloat)
{
UIView.animateWithDuration(0.2, delay: 0, options: UIViewAnimationOptions.CurveEaseIn, animations: {
self.topMarginConstraint.constant = newMargin;
}, completion: { finished in
println("Animation end!")
})
}
检查一下它工作正常。
我正在尝试将参数传递给函数以动态更改动画块中的布局约束。
这个有效:
func moveKeyboard (up: Bool, newMargin: Int)
{
UIView.animateWithDuration(0.2, delay: 0, options: .CurveEaseIn, animations: {
self.topMarginConstraint.constant=10;
}, completion: { finished in
println("Animation end!")
})
}
这不是(我收到错误 "Could not find member CurveEaseIn"):
func moveKeyboard (up: Bool, newMargin: Int)
{
UIView.animateWithDuration(0.2, delay: 0, options: .CurveEaseIn, animations: {
self.topMarginConstraint.constant=newMargin;
}, completion: { finished in
println("Animation end!")
})
}
我应该如何定义我的函数才能在动画块中使用 newMargin 参数?
这是因为,"constant" 是 "CGFLoat" 类型,而你正在传递 "Int":
func moveKeyboard (up: Bool, newMargin: CGFloat)
{
UIView.animateWithDuration(0.2, delay: 0, options: UIViewAnimationOptions.CurveEaseIn, animations: {
self.topMarginConstraint.constant = newMargin;
}, completion: { finished in
println("Animation end!")
})
}
检查一下它工作正常。