Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save dipkasyap/d2a54917884d79edfa58d9b9befdc20f to your computer and use it in GitHub Desktop.
Save dipkasyap/d2a54917884d79edfa58d9b9befdc20f to your computer and use it in GitHub Desktop.
//
// indicator.swift
// mTaxi
//
// Created by Saroj on 4/6/16.
// Copyright © 2016 Saroj. All rights reserved.
//
import UIKit
class Indicator{
let window:UIWindow? = (UIApplication.sharedApplication().delegate?.window)!
var dimView:UIView?
var imageView:UIImageView?
var circleImageView:UIImageView?
var spinnerSize:CGFloat = 80
var centerImage:UIImage = UIImage(named: "loading_inner")!
var circleImage:UIImage = UIImage(named: "loading")!
var stableCircleView:UIView?
var presentView:UIView?
func startAnimating(){
presentView = window!
let rotationAnimation = CABasicAnimation(keyPath: "transform.rotation.z")
rotationAnimation.fromValue = 0 * CGFloat(M_PI/180)
rotationAnimation.toValue = 360 * CGFloat(M_PI/180)
let innerAnimationDuration : CGFloat = 1.0
rotationAnimation.duration = Double(innerAnimationDuration)
rotationAnimation.repeatCount = HUGE
circleImageView = UIImageView(frame: CGRectMake(presentView!.center.x - (spinnerSize) / 2 , presentView!.center.y - (spinnerSize) / 2, spinnerSize, spinnerSize))
imageView = UIImageView(frame: CGRectMake(presentView!.center.x - (spinnerSize - 5) / 2 , presentView!.center.y - (spinnerSize - 5) / 2, spinnerSize - 5, spinnerSize - 5))
imageView!.image = centerImage
circleImageView?.image = circleImage
dimView = UIView(frame: (window?.frame)!)
dimView?.backgroundColor = UIColor.blackColor()
dimView?.alpha = 0.5
presentView!.addSubview(dimView!)
presentView!.addSubview(circleImageView!)
presentView!.addSubview(imageView!)
self.circleImageView?.layer.addAnimation(rotationAnimation, forKey: "rotateInner")
}
func stopAnimating(){
dimView?.removeFromSuperview()
circleImageView?.removeFromSuperview()
imageView?.removeFromSuperview()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment