我有一个按钮调用这个IBAction函数。当应用程序运行而不是点击按钮时,活动指示器会立即启动,当函数完成其工作时会按预期消失,然后再也不会出现。这看起来是一个非常简单的界面,但我很困惑。有什么想法吗?
@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) }
}
最佳答案
听起来您的故事板中的活动视图上的isAnimating
属性设置为true。确保它为false,并且hidesWhenStopped
属性为true。
那你的代码就不能按公布的那样工作了。如果希望微调器在对UIImageWriteToSavedPhotosAlbum
的调用完成时停止设置动画,则需要提供completionTarget
和completionSelector
。像这样的:
(编辑为使用正确的方法签名来完成方法)
UIImageWriteToSavedPhotosAlbum(
image,
self,
"image:didFinishSavingWithError:contextInfo:",
nil)
以及写入完成后要调用的方法:
func image(image: UIImage,
didFinishSavingWithError
error: NSErrorPointer,
contextInfo: UnsafePointer<Void>)
{
activityIndicator.stopAnimating()
if error != nil
{
println(error)
}
}
关于ios - 事件指示器在调用函数之前启动,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/30879725/