美文网首页swift-动画锦集
点击按钮,左右摇摆动画

点击按钮,左右摇摆动画

作者: 谌文 | 来源:发表于2019-11-12 11:46 被阅读0次

代码实现方法

    //MARK: - 按钮点击
    @objc func buttonClick(button: UIButton) {
        let animation = CAKeyframeAnimation()
        let shake = 10
        animation.keyPath = "transform.translation.x"
        animation.values = [-shake, shake, -shake]
        animation.repeatCount = 3;
        animation.duration = 0.1
        animation.isRemovedOnCompletion = true
        self.layer.add(animation, forKey: "shake")
    }

相关文章

网友评论

    本文标题:点击按钮,左右摇摆动画

    本文链接:https://www.haomeiwen.com/subject/stvfictx.html