Created
August 1, 2019 06:22
-
-
Save Haeuncs/55336e4d4dac9f2391ec88a66e5fad1a to your computer and use it in GitHub Desktop.
ImageView scale transform when loading in swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class LoadingViewWithLogo: NSObject { | |
private static let shared = LoadingViewWithLogo() | |
private var backView: UIView? | |
private var fitcoLogoImageView: UIImageView? | |
private override init() { } | |
static func show() { | |
let backView = UIView(frame: .zero) | |
backView.backgroundColor = UIColor.black.withAlphaComponent(0.4) | |
let popupView = UIImageView(image: UIImage(named: "imgLogoBlack")) | |
if let window = UIApplication.shared.keyWindow { | |
window.addSubview(backView) | |
backView.frame = window.frame | |
backView.addSubview(popupView) | |
popupView.center = backView.center | |
shared.backView?.removeFromSuperview() | |
shared.backView = backView | |
shared.fitcoLogoImageView?.removeFromSuperview() | |
shared.fitcoLogoImageView = popupView | |
shared.startAnimate() | |
} | |
} | |
func startAnimate(){ | |
UIView.animate(withDuration: 1.0, delay:0, options: [.repeat, .autoreverse], animations: { | |
self.fitcoLogoImageView?.transform = CGAffineTransform(scaleX: 1.2, y: 1.2) | |
}, completion: {completion in | |
self.fitcoLogoImageView?.transform = CGAffineTransform(scaleX: 1, y: 1) | |
}) | |
} | |
static func hide() { | |
if let popupView = shared.fitcoLogoImageView, let backView = shared.backView { | |
DispatchQueue.main.async { | |
popupView.stopAnimating() | |
popupView.removeFromSuperview() | |
backView.removeFromSuperview() | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Scale animation works in the centered imageView.