我想在Scroll视图中生成图像(就像视频开始在默认的ios播放器中播放一样)。
let imageView = UIImageView()
let asset :AVAsset = AVURLAsset.init(url: url as URL)
let assetImgGenerate : AVAssetImageGenerator = AVAssetImageGenerator(asset: asset)
assetImgGenerate.appliesPreferredTrackTransform = true
assetImgGenerate.requestedTimeToleranceAfter = kCMTimeZero;
assetImgGenerate.requestedTimeToleranceBefore = kCMTimeZero;
var img = UIImage()
assetImgGenerate.appliesPreferredTrackTransform = true
let thumbTime: CMTime = asset.duration
let times = thumbTime as NSValue
assetImgGenerate.generateCGImagesAsynchronously(forTimes: [times], completionHandler: {( requestedTime, image, actualTime,result, error) -> Void in
img = UIImage(cgImage: image!)
imageView.image = img
})
scrollView.backgroundColor = UIColor.black
scrollView.contentSize = CGSize(width: CGFloat(imageView.frame.width), height: 0)
scrollView.addSubview(imageView)}
这并没有给出任何输出。如何将图像生成为要在滚动视图中显示的序列?
我在这里做错了什么?
答案 0 :(得分:1)
您的代码中存在一些错误: