Created
July 12, 2015 16:22
-
-
Save minsOne/e5c37e9abef2fff594ab to your computer and use it in GitHub Desktop.
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
// | |
// 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