我有一个 unwind segue,它可以返回到前一个控制器并将图像保存到 PHAsset 库。展开转场有效,保存有效,唯一的问题是它在图像保存之前展开。因此,图像不会呈现在展开的视图控制器上,因为视图控制器是在保存图片之前呈现的(保存图像需要一点时间,而它会返回到视图控制器非常快)。我想知道是否有任何方法可以仅在保存照片后才可以放松到以前的控制器,而不是立即。
这是我的代码:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "savePicture" {
//Image to be saved
let newImage = self.appraisalPic.image
//Store picture to PHAssets
let priority = DISPATCH_QUEUE_PRIORITY_DEFAULT
dispatch_async(dispatch_get_global_queue(priority, 0), {
PHPhotoLibrary.sharedPhotoLibrary().performChanges({
let createAssetRequest = PHAssetChangeRequest.creationRequestForAssetFromImage(newImage)
let assetPlaceholder = createAssetRequest.placeholderForCreatedAsset
let albumChangeRequest = PHAssetCollectionChangeRequest(forAssetCollection: self.assetCollection, assets: self.photosAsset)
albumChangeRequest.addAssets([assetPlaceholder])
}, completionHandler: {(success, error)in
dispatch_async(dispatch_get_main_queue(), {
NSLog("Adding Image to Library -> %@", (success ? "Success":"Error!"))
//Need code here which doesn't do segue until AFTER picture is saved
})
})
})
}
}