Swift按钮动画

//点击按钮抖动动画
@objc func homeBottomBtnMethod(_ sender:UIButton){
sender.transform = CGAffineTransform(scaleX: 0.7, y: 0.7)

            UIView.animateKeyframes(withDuration: 0.5, delay: 0, options: UIViewKeyframeAnimationOptions(rawValue: 0), animations: {
                sender.transform = CGAffineTransform(scaleX: 1, y: 1)
            }) { (true) in
            }

}
//其他按钮弹动画,给按钮本身添加动画

            let pulse = CASpringAnimation(keyPath: "transform.scale")
            pulse.damping = 7.5
            pulse.fromValue = 1.25
            pulse.toValue = 1.0
            pulse.duration = pulse.settlingDuration
            self.getBottomBtn.layer.add(pulse, forKey: nil)
            self.publishBottomBtn.layer.add(pulse, forKey: nil)

你可能感兴趣的:(Swift按钮动画)