Skip to content

Instantly share code, notes, and snippets.

@minsOne
Created July 12, 2015 16:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save minsOne/e5c37e9abef2fff594ab to your computer and use it in GitHub Desktop.
Save minsOne/e5c37e9abef2fff594ab to your computer and use it in GitHub Desktop.
//
// ViewController.swift
// asyncalertview
//
// Created by JungMin Ahn on 2015. 7. 12..
// Copyright (c) 2015년 JungMin Ahn. All rights reserved.
//
import UIKit
class ViewController: UIViewController {
var isTap = false
override func viewDidLoad() {
super.viewDidLoad()
var taps = UITapGestureRecognizer(target: self, action: Selector("tapp"))
self.view.gestureRecognizers = [taps]
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func tapp() {
isTap = !isTap
if isTap {
LoadingHUD.show()
}
else {
LoadingHUD.hide()
}
}
}
class LoadingHUD: NSObject {
private static let sharedInstance = LoadingHUD()
private var popupView: UIImageView?
class func show() {
let popupView = UIImageView(frame: CGRectMake(0, 0, 300, 300))
popupView.backgroundColor = UIColor.blackColor()
popupView.animationImages = LoadingHUD.getAnimationImageArray()
popupView.animationDuration = 4.0
popupView.animationRepeatCount = 0
if let window = UIApplication.sharedApplication().keyWindow {
window.addSubview(popupView)
popupView.center = window.center
popupView.startAnimating()
sharedInstance.popupView?.removeFromSuperview()
sharedInstance.popupView = popupView
}
}
class func hide() {
if let popupView = sharedInstance.popupView {
popupView.stopAnimating()
popupView.removeFromSuperview()
}
}
private class func getAnimationImageArray() -> [UIImage] {
var animationArray: [UIImage] = []
animationArray.append(UIImage(named: "day_1")!)
animationArray.append(UIImage(named: "day_2")!)
animationArray.append(UIImage(named: "day_3")!)
animationArray.append(UIImage(named: "day_4")!)
return animationArray
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment