Subclassing UIButton and overriding touch events - not working

Instead of calling super in the completion block of touchesCancelled and touchesEnded methods I called self.sendActionsForControlEvents(UIControlEvents.TouchUpInside) in there.


Not sure exactly why yet, but you need to call super.touchesEnded(touches, with: event) outside the animation

So (Swift 5)

override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
    UIView.animate(withDuration: 0.5,
        delay: 0,
        usingSpringWithDamping: 0.2,
        initialSpringVelocity: 6.0,
        options: UIView.AnimationOptions.allowUserInteraction,
        animations: { () -> Void in
            self.transform = CGAffineTransform.identity
        }) { (Bool) -> Void in
    }
    super.touchesEnded(touches, with: event)
}