gpt4 book ai didi

ios - 事件指示器在调用函数之前启动

转载 作者:行者123 更新时间:2023-11-28 11:17:24 26 4
gpt4 key购买 nike

我有一个调用此 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) }
}

最佳答案

听起来您在 Storyboard 中将事件 View 的 isAnimating 属性设置为 true。确保它为假,并且 hidesWhenStopped 属性为真。

那么您的代码将无法像发布的那样工作。如果您希望微调器在对 UIImageWriteToSavedPhotosAlbum 的调用完成时停止动画,您需要提供一个 completionTargetcompletionSelector。像这样:

(编辑为完成方法使用正确的方法签名)

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/

26 4 0
文章推荐: css - HTML5/CSS : possible to define a