贡献作者 -【XJDomain】
博客XJ: https://my.oschina.net/shengbingli/blog
GitHub直播地址: https://github.com/lishengbing/XJDomainLive
直接调用这个方法就可以,前提是资源包需要导入你的项目当中:
----资源包下载地址: https://github.com/lishengbing/XJDomainLive
----克隆上面项目: Classes -> OTher -> XJDomain.bundle包,直接拷贝到你的项目就可以使用了
func animationForHeart() {
let imageV = UIImageView()
imageV.frame = CGRect(x: kScreenW - CGFloat(84), y: kScreenH - CGFloat(58), width: 25, height: 25)
imageV.backgroundColor = UIColor.clear
imageV.clipsToBounds = true
self.view.addSubview(imageV)
// UInt32(0.9)
let starX : CGFloat = CGFloat(round(Double(arc4random() % 300)))
var scale = round(Double(arc4random() % 2 + 1))
let speed = 1 / round(Double(arc4random() % 900) ) + 0.4
let imageName = Int(round(Double(arc4random() % 10)))
let name = String(format: "XJDomain.bundle/heart%d.png", imageName)
imageV.image = UIImage(named: name)
let x = (kScreenW - starX) * 1.5
if scale >= 1.2 {
scale = 1.2
}
UIView.animate(withDuration: 7 * speed, animations: {
imageV.frame = CGRect(x: x, y: kScreenH - 400, width: CGFloat(25 * scale), height: CGFloat(25 * scale))
}, completion: { (_) in
imageV.removeFromSuperview()
})
}