IOS仿京东收藏心跳动画

2017-01-14 10:24:22来源:http://www.jianshu.com/p/4f0f5ea0d17a作者:疏雨萧萧Go人点击

最近在看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")



最新文章

123

最新摄影

微信扫一扫

第七城市微信公众平台