Activity 指标在调用函数之前启动
Activity indicator starts before function is called
我有一个调用此 IBAction 函数的按钮。 activity 指示器在应用程序运行时启动,而不是在点击按钮时启动,在函数完成其工作时按预期消失,然后再也不会出现。这似乎是一个非常简单的界面,但我很难过。有什么想法吗?
@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) }
}
听起来您在情节提要中将 activity 视图上的 isAnimating
属性 设置为 true。确保它是假的,并且 hidesWhenStopped
属性 是真的。
那么您的代码将无法像发布的那样工作。如果您希望微调器在 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)
}
}
我有一个调用此 IBAction 函数的按钮。 activity 指示器在应用程序运行时启动,而不是在点击按钮时启动,在函数完成其工作时按预期消失,然后再也不会出现。这似乎是一个非常简单的界面,但我很难过。有什么想法吗?
@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) }
}
听起来您在情节提要中将 activity 视图上的 isAnimating
属性 设置为 true。确保它是假的,并且 hidesWhenStopped
属性 是真的。
那么您的代码将无法像发布的那样工作。如果您希望微调器在 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)
}
}