iOS swift : generateCGImagesAsynchronouslyForTimes takes too long and freezes the app?

混江龙づ霸主 提交于 2019-12-12 18:15:25

问题


I'm getting video thumbnails asynchronously with the following code:

let imgGenerator = AVAssetImageGenerator(asset: asset)

            imgGenerator.generateCGImagesAsynchronouslyForTimes([NSValue(CMTime: CMTimeMake(1, 30))]) {(time1, image, time2, result, error) -> Void in

                if (result == .Succeeded) {

                    dispatch_async(dispatch_get_main_queue()) {
                        thumbnailImageView.image = UIImage(CGImage: image!)
                    }

                    NSLog("SUCCESS!")
                }
            }

I don't understand why it freezes the app but for example if I use this for 20 tableview cells it takes more than 20 seconds to load and the app will not segue and show the view before it finishes downloading all. Why am I missing here ?

来源:https://stackoverflow.com/questions/37394920/ios-swift-generatecgimagesasynchronouslyfortimes-takes-too-long-and-freezes-th

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!