Reputation: 857
I have this function that animates a UIImageView:
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")
}
After I upgraded to Swift 3 I started receiving the following error:
No '+" candidates produce the expected contextual result type 'AnyObject'
I read in a similar question that the function should have return values but I don't know how to implement this. I would appreciate your help resolving this error
Upvotes: 1
Views: 2638
Reputation: 11250
If you're expecting just values typed as CGFloat
change it by:
func playMoveIconAnimation(_ icon : UIImageView, values: [CGFloat]) {
let yPositionAnimation = createAnimation("position.y", values:values, duration:duration / 2)
icon.layer.add(yPositionAnimation, forKey: "yPositionAnimation")
}
Upvotes: 1
Reputation: 857
Thanks to Nirav D and Leo Dabus I was able to fix it, I don't have an explanation but this is the code that worked at the end:
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")
}
Upvotes: 0