[英]Activity indicator starts before function is called
我有一个调用此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
中将活动视图上的isAnimating
属性设置为true。 确保它为假,并且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)
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.