I have a button that calls this IBAction function. The activity indicator starts as soon as the app runs instead of when the button is tapped, disappears as expected when the function completes its work then never appears again. This seems like a really simple interface thing but I'm stumped. Any ideas?
@IBAction func saveToCamera() {
// Start the spinner
activityIndicator.startAnimating()
//Create the UIImage
UIGraphicsBeginImageContext(canvas.frame.size)
canvas.layer.renderInContext(UIGraphicsGetCurrentContext())
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
//Save it to the camera roll
UIImageWriteToSavedPhotosAlbum(image, self, "image:didFinishSavingWithError:contextInfo:", nil)
}
func image(image: UIImage, didFinishSavingWithError error: NSErrorPointer, contextInfo:UnsafePointer<Void>) {
activityIndicator.stopAnimating()
if error != nil {
println(error) }
}
It sounds like you have the
isAnimating
property on the activity view set to true in your storyboard. make sure it's false, and that thehidesWhenStopped
property is true.Then your code won't work as posted. If you want the spinner to stop animating when the call to
UIImageWriteToSavedPhotosAlbum
is complete, you need to provide acompletionTarget
andcompletionSelector
. Something like this:(Edited to use correct method signature for completion method)
And a method to be called once the write is complete: