Closed OptTrader closed 8 years ago
yes you can, just add custom animation class. Look section "Creating Custom Animations" in README.md. change image in this methods:
override func playAnimation(icon : UIImageView, textLable : UILabel) {
// add animation
.....
icon.image = selectedImage
....
}
// method call when Tab Bar Item is deselected
override func deselectAnimation(icon : UIImageView, textLable : UILabel, defaultTextColor : UIColor) {
// add animation
.....
icon.image = normalImage
....
}
I am going crazy, How can I access "selectedImage" from in custom animation.
Hi, I have the same question with @savasadar. How can I access selectedImage in CustomAnimation class?
@savasadar I solved selectedImage by create a img
and a selectedImg
in a custom RAMAnimatedTabBarItem. Because the original image
and selectedImage
somehow effect each other.
class HostAnimatedTabBarItem: RAMAnimatedTabBarItem {
var img: UIImage?
var selectedImg: UIImage?
}
Then also create a weak item: RAMAnimatedTabBarItem in a overrided RAMItemAnimation class.
class HostBounceAnimation: RAMItemAnimation {
weak var tabBarItem: RAMAnimatedTabBarItem?
}
let item = HostAnimatedTabBarItem(title: ..., image: ..., selectedImage: ...)
let animation = HostBounceAnimation()
item.animation = animation
animation.tabBarItem = item
Final step is assigning your item with your new img or selectedImg property.
override func playAnimation(_ icon: UIImageView, textLabel: UILabel) {
playBounceAnimation(icon)
textLabel.textColor = Configuration.Theme.darkBlue
guard let item = tabBarItem as? HostAnimatedTabBarItem else {
fatalError("item selected image is nil")
}
icon.image = item.selectedImg
}
Do the same thing with your deselect method. I think it will work like a charm.
Is it possible to work on the animation with 2 different images for each tab (selected & unselected)?
I'm assuming it doesn't work. Just want to check.