我有这个动画来动画UIImageView:
datatable.controller.js
升级到Swift 3后,我开始收到以下错误:
override func deselectAnimation(_ icon : UIImageView, textLabel : UILabel, defaultTextColor : UIColor) {
playMoveIconAnimation(icon, values:[icon.center.y + 4.0, icon.center.y])
playDeselectLabelAnimation(textLabel)
textLabel.textColor = defaultTextColor
if let iconImage = icon.image {
let renderImage = iconImage.withRenderingMode(.alwaysTemplate)
icon.image = renderImage
icon.tintColor = defaultTextColor
}
}
func playMoveIconAnimation(_ icon : UIImageView, values: [AnyObject]) {
let yPositionAnimation = createAnimation("position.y", values:values, duration:duration / 2)
icon.layer.add(yPositionAnimation, forKey: "yPositionAnimation")
}
我在类似question中读到函数应该有返回值,但我不知道如何实现它。非常感谢您帮助解决此错误
答案 0 :(得分:1)
如果您希望仅将CGFloat
类型的值更改为:
func playMoveIconAnimation(_ icon : UIImageView, values: [CGFloat]) {
let yPositionAnimation = createAnimation("position.y", values:values, duration:duration / 2)
icon.layer.add(yPositionAnimation, forKey: "yPositionAnimation")
}
答案 1 :(得分:0)
感谢Nirav D和Leo Dabus,我能够解决它,我没有解释,但这是最终有效的代码:
override func deselectAnimation(_ icon : UIImageView, textLabel : UILabel, defaultTextColor : UIColor) {
playMoveIconAnimation(icon, values: [CGFloat(icon.center.y + 4.0)])
playDeselectLabelAnimation(textLabel)
textLabel.textColor = defaultTextColor
if let iconImage = icon.image {
let renderImage = iconImage.withRenderingMode(.alwaysTemplate)
icon.image = renderImage
icon.tintColor = defaultTextColor
}
}
func playMoveIconAnimation(_ icon : UIImageView, values: [Any]) {
let yPositionAnimation = createAnimation("position.y", values:values as [AnyObject], duration:duration / 2)
icon.layer.add(yPositionAnimation, forKey: "yPositionAnimation")
}