IOS仿京东收藏心跳动画

最近在看IOS动画相关的东西,正好看到京东收藏商品的时候有个心跳的动画,于是研究了一下,代码很简单

        let heart = UIButton(frame: CGRect(x: APP_FRAME_WIDTH*0.5-25, y: 200, width: 50, height: 50))
        self.view.addSubview(heart)
        heart.setImage(UIImage(named: "heart") , for: .normal)
        heart.setImage(UIImage(named: "hearted") , for: .selected)
        heart.addTarget(self, action: #selector(ViewController.click(_:)), for: .touchUpInside)

点击事件:

        button.isSelected = !button.isSelected
        let k = CAKeyframeAnimation.init(keyPath: "transform.scale")
        k.values = [0.1,1.0,1.5]
        k.keyTimes = [0.0,0.8,1.0]
        k.calculationMode = kCAAnimationLinear
        button.layer.add(k, forKey: "SHOW")

你可能感兴趣的:(IOS仿京东收藏心跳动画)