Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Haeuncs/55336e4d4dac9f2391ec88a66e5fad1a to your computer and use it in GitHub Desktop.
Save Haeuncs/55336e4d4dac9f2391ec88a66e5fad1a to your computer and use it in GitHub Desktop.
ImageView scale transform when loading in swift
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()
}
}
}
}
@Haeuncs
Copy link
Author

Haeuncs commented Aug 1, 2019

Scale animation works in the centered imageView.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment