I want to be able to add custom animations to subclasses of UITableViewCell that would override methods such as:
override func setHighlighted(highlighted: Bool, animated: Bool) {
}
override func setSelected(selected: Bool, animated: Bool) {
}
and match the animation curve and animation duration for the default animations those methods perform.
In other words, how can I find the information about the current animations provided by Apple. I need this in order to add my own custom animations that perfectly matches the default ones
You can subclass your custom cell in your table view.
And here I create a simple example in Swift where I change the value of a label inside the cell:
import UIKit
class userTableViewCell: UITableViewCell {
@IBOutlet weak var userLabel: UILabel!
override func awakeFromNib() {
super.awakeFromNib()
self.highlighted = false
self.userLabel.alpha = 0.0
// Initialization code
}
override func setSelected(selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
if selected {
self.highlighted = true
} else {
self.highlighted = false
}
// Configure the view for the selected state
}
override var highlighted: Bool {
get {
return super.highlighted
}
set {
if newValue {
// you could put some animations here if you want
UIView.animateWithDuration(0.7, delay: 1.0, options: .CurveEaseOut, animations: {
self.userLabel.text = "select"
self.userLabel.alpha = 1.0
}, completion: { finished in
print("select")
})
}
else {
self.userLabel.text = "unselect"
}
super.highlighted = newValue
}
}
}
And with the storyboard what you must have:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With