我有一個調用此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) }
}
什麼屬性有您設置故事板場景中的活動指示器? – Paulw11
你有更大的問題 - 你的問題是理解同步和異步編程。您已將所有代碼放在一個函數中,最後一行是stopAnimating(),這意味着在您調用此函數之後,動畫師將永遠不會顯示,因爲您正在啓動它,但稍後您將停止它,因此它永遠不會顯示給用戶。鄧肯已經展示瞭如何讓它停止。確保你明白爲什麼你所做的不能工作。 – Gruntcakes