I have the following code and I can't work out why my Activity Indicator is not showing. I am not sure why it won't show. I basically have the start and stop animating functions wrapped around code code that connects to an API and returns JSON Data. Depending on the connection speed the transaction will varying in time. I want this Activity Indicator to show while this is occurring. Does it have to do with the DispatchQueue
self.activityIndicatorView = ActivityIndicatorView(title: "Converting...", center: self.view.center)
self.view.addSubview(self.activityIndicatorView.getViewActivityIndicator())
self.activityIndicatorView.startSpinner()
UIApplication.shared.beginIgnoringInteractionEvents()
//Run the fetchConversion regardless
//Codes is run here to get a JSON response removed to clarity but this can take some time depending on internet connection speeds.
UIApplication.shared.endIgnoringInteractionEvents()
self.activityIndicatorView.stopSpinner()
calls this function in Activity Indicator View
class ActivityIndicatorView
{
var view: UIView!
var activityIndicator: UIActivityIndicatorView!
var title: String!
init(title: String, center: CGPoint, width: CGFloat = 200.0, height: CGFloat = 50.0)
{
self.title = title
let x = center.x - width/2.0
let y = center.y - height/2.0
self.view = UIView(frame: CGRect(x: x, y: y, width: width, height: height))
self.view.backgroundColor = #colorLiteral(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0) // UIColor(red: 255.0/255.0, green: 204.0/255.0, blue: 51.0/255.0, alpha: 0.5)
self.view.layer.cornerRadius = 10
self.activityIndicator = UIActivityIndicatorView(frame: CGRect(x: 0, y: 0, width: 50, height: 50))
self.activityIndicator.color = UIColor.black
self.activityIndicator.hidesWhenStopped = false
let titleLabel = UILabel(frame: CGRect(x: 60, y: 0, width: 200, height: 50))
titleLabel.text = title
titleLabel.textColor = UIColor.black
self.view.addSubview(self.activityIndicator)
self.view.addSubview(titleLabel)
}
func getViewActivityIndicator() -> UIView
{
return self.view
}
func startSpinner()
{
self.activityIndicator.startAnimating()
UIApplication.shared.beginIgnoringInteractionEvents()
}
func stopSpinner()
{
self.activityIndicator.stopAnimating()
UIApplication.shared.endIgnoringInteractionEvents()
self.view.removeFromSuperview()
}
}
Any Help much appreciated