一直在努力使其工作。我正在生成视频缩略图,但是在收藏夹视图中它的负载确实很大。我想缓存它们,但找不到解决方案。
这是我正在使用的代码:
func previewImageFromVideo(url:NSURL) -> UIImage? {
let asset = AVAsset(url: url as URL)
let imageGenerator = AVAssetImageGenerator(asset:asset)
imageGenerator.appliesPreferredTrackTransform = true
imageGenerator.maximumSize = CGSize(width: 250, height: 120)
var time = asset.duration
time.value = min(time.value,2)
do {
let imageRef = try imageGenerator.copyCGImage(at: time, actualTime: nil)
return UIImage(cgImage: imageRef)
} catch {
return nil
}
}
Run Code Online (Sandbox Code Playgroud)
我把它们做得很小,但每次都仍连接到服务器。请帮忙。
我试图在单元格外部的集合视图中更改自定义视图单元格的某些属性,但我无法弄清楚我做错了什么:
在 cellForItem 我有:
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "PatientProfileCell", for: indexPath) as! PatientQuestionCell
if Auth.auth().currentUser?.uid == userID {
cell.commentButton.setTitle("Edit post", for: .normal)
cell.commentButton.addTarget(self, action: #selector(editPostAction), for: .touchUpInside)
}
} else {
print("Not the current user for collection view")
}
}
Run Code Online (Sandbox Code Playgroud)
在这里一切正常,但是当我触发动作时什么也没有发生。这是功能:
//post actions
func editPostAction() {
print("Edit post Enabled")
let cell = PatientQuestionCell()
cell.questionView.isEditable = true
cell.questionView.isSelectable = true
cell.questionView.isScrollEnabled = true
cell.questionView.becomeFirstResponder()
}
Run Code Online (Sandbox Code Playgroud)
如何使用此功能更改单元格的属性?