swift-动画锦集

点击按钮,左右摇摆动画

2019-11-12  本文已影响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")
    }
上一篇 下一篇

猜你喜欢

热点阅读