I am attempting to create a custom button press animation for a tvOS button, I have already created a didUpdateFocusInContext function for focus update animations. I tried to overload the highlighted variable didSet to animate the press of the button (its custom, not system), but what happens is it works mostly, but there is one flaw. When you press down, then move the focus off of the button, it never fires the highlighted didSet for setting it to false from focusing off of the button while down. Does this mean it stays highlighted? Doesn't seem like it. Any suggestions? Thanks!
class UIButtonTV: UIButton {
override var highlighted : Bool {
didSet {
if ( highlighted == true ) {
UIView.animateWithDuration(0.07) {
self.setTitleColor(UIColor.whiteColor(), forState: .Normal)
}
} else {
UIView.animateWithDuration(0.07) {
self.setTitleColor(UIColor.blackColor(), forState: .Normal)
}
}
}
}
override func didUpdateFocusInContext(context: UIFocusUpdateContext, withAnimationCoordinator coordinator: UIFocusAnimationCoordinator) {
super.didUpdateFocusInContext(context, withAnimationCoordinator: coordinator)
if(context.nextFocusedView == self){
coordinator.addCoordinatedAnimations({
self.transform = CGAffineTransformMakeScale(1.25, 1.25)
self.layoutIfNeeded()
},
completion: nil
)
} else if (context.previouslyFocusedView == self) {
coordinator.addCoordinatedAnimations({
self.transform = CGAffineTransformMakeScale(1.0, 1.0)
self.layoutIfNeeded()
},
completion: nil
)
}
}
}