| | |
| | | private var treeImage = UIImageView() |
| | | private var aPNGTreeImageView:APNGImageView? |
| | | private var aPNGSunImageView:APNGImageView? |
| | | private var aPNGActionImageView:APNGImageView? |
| | | |
| | | |
| | | override func viewDidDisappear(_ animated: Bool) { |
| | |
| | | } |
| | | |
| | | |
| | | if let treeApngImage = try? APNGImage(fileURL: Bundle.main.url(forResource: "apngb-animated", withExtension: "png")!,decodingOptions: .notCacheDecodedImages){ |
| | | if let treeApngImage = try? APNGImage(fileURL: Bundle.main.url(forResource: "apngb-animated", withExtension: "png")!){ |
| | | treeApngImage.numberOfPlays = 1 |
| | | aPNGTreeImageView = APNGImageView(image: treeApngImage) |
| | | let tap = UITapGestureRecognizer(target: self, action: #selector(jumpAction)) |
| | |
| | | } |
| | | |
| | | @objc func jumpAction(){ |
| | | let springAnimation = CASpringAnimation(keyPath: "transform.scale.y") |
| | | springAnimation.fromValue = 1 |
| | | springAnimation.toValue = 1.06 |
| | | springAnimation.initialVelocity = 0.5 //初速度 |
| | | springAnimation.repeatCount = 1 |
| | | springAnimation.duration = 3.0 |
| | | springAnimation.mass = 0.4 //增加该值会增大弹性效果,即震动次数更多、幅度更大 |
| | | springAnimation.stiffness = 100 //增大stiffness会减少震动次数,减小 |
| | | springAnimation.damping = 1 |
| | | springAnimation.isRemovedOnCompletion = false |
| | | springAnimation.fillMode = .forwards |
| | | aPNGTreeImageView?.layer.add(springAnimation, forKey: nil) |
| | | |
| | | if let waterApngImage = try? APNGImage(fileURL: Bundle.main.url(forResource: "apngb-animated-flow", withExtension:"png")!){ |
| | | waterApngImage.numberOfPlays = 2 |
| | | aPNGActionImageView = APNGImageView(image: waterApngImage) |
| | | aPNGActionImageView!.alpha = 0 |
| | | aPNGSunImageView?.contentMode = .scaleToFill |
| | | view.addSubview(aPNGActionImageView!) |
| | | aPNGActionImageView!.snp.makeConstraints { make in |
| | | make.center.equalToSuperview().inset(UIEdgeInsets(top: 90, left: 140, bottom: 0, right: 0)) |
| | | make.width.equalTo(200) |
| | | make.height.equalTo(150) |
| | | } |
| | | UIView.animate(withDuration: 0.5) { |
| | | self.aPNGActionImageView!.alpha = 1.0 |
| | | } |
| | | aPNGActionImageView!.startAnimating() |
| | | |
| | | aPNGActionImageView!.onOnePlayDone.delegate(on: self) {[unowned self] a,b in |
| | | if b == 2{ |
| | | UIView.animate(withDuration: 0.5) { |
| | | self.aPNGActionImageView!.alpha = 0 |
| | | }completion: { _ in |
| | | self.aPNGActionImageView!.removeFromSuperview() |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | // let springAnimation = CASpringAnimation(keyPath: "transform.scale.y") |
| | | // springAnimation.fromValue = 1 |
| | | // springAnimation.toValue = 1.06 |
| | | // springAnimation.initialVelocity = 0.5 //初速度 |
| | | // springAnimation.repeatCount = 1 |
| | | // springAnimation.duration = 3.0 |
| | | // springAnimation.mass = 0.4 //增加该值会增大弹性效果,即震动次数更多、幅度更大 |
| | | // springAnimation.stiffness = 100 //增大stiffness会减少震动次数,减小 |
| | | // springAnimation.damping = 1 |
| | | // springAnimation.isRemovedOnCompletion = false |
| | | // springAnimation.fillMode = .forwards |
| | | // aPNGTreeImageView?.layer.add(springAnimation, forKey: nil) |
| | | } |
| | | } |
| | | |