IOS仿京东收藏心跳动画

fjzhenghua 4年前
   <p>最近在看IOS动画相关的东西,正好看到京东收藏商品的时候有个心跳的动画,于是研究了一下,代码很简单</p>    <pre>  <code class="language-objectivec">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)</code></pre>    <p>点击事件:</p>    <pre>  <code class="language-objectivec">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")</code></pre>    <p> </p>    <p>来自:http://www.jianshu.com/p/4f0f5ea0d17a</p>    <p> </p>