IOS仿京东收藏心跳动画

作者: 疏雨萧萧Go | 来源:发表于2016-10-31 16:01 被阅读780次

最近在看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仿京东收藏心跳动画

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