在UITableViewCell中的UIImageView或AVPlayer(照片或视频) [英] UIImageView or AVPlayer (photo or video) in UITableViewCell

查看:391
本文介绍了在UITableViewCell中的UIImageView或AVPlayer(照片或视频)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

1)我有一个应用程序与 UITableView 。这个单元格有一些像 UILabel UIButton (喜欢,描述等)的内容,视频(取决于文章的类型(如 instagram 经典文章))。所以细胞可以是两种类型之一:有视频或有照片。其他信息,限制,尺寸等是相似的。



现在我只有一个自定义单元格类型,它包含 UIView (都是照片/视频)。我在这个 UIView 中添加了 AVPlayer UIImageView C>。它有效,但我认为这是如何做到这一点的一个坏方法。另外这是非常糟糕的逻辑层。



如何正确地做到这一点?我应该有2个自定义单元格类型?或者,也许有一些图书馆存在吗?



2)我正在从 Firebase-storage 。这个操作是异步的。因此,我在 PostItem 中存储介质 MediaAspectRatio code>。我正在使用它来缩放 UIView ,之后单元格显示为不裁剪媒体。我也不确定,这是正确的逻辑。



任何建议表示赞赏。谢谢。

解决方案

两种方式都可以。然而,有2种不同的单元格类型可能是一个更清洁的实现。



另外有2个单元格类型将使您无需交换imageView与AvPlayer图层,可能会因为单元复用而使事情变复杂。



至于你所做的大小调整,只要确保你没有破坏任何约束,逻辑听起来不错。



图像视图和AvPlayers拥有AspectFill的概念,这就是你想要做的事情,不要打破你的媒体的纵横比,而不是在同一时间裁剪。

AspectFit另一方面将保持长宽比和裁切。

1) I have an application with UITableView. This cell has some content like UILabel, UIButton (likes, description, etc.) and it also should store image or video (depends on type of post (like instagram classic post)). So cells can be one of the 2 types: with video or with photo. Other info, constraints, sizes etc. are similar.

At the moment I have only one custom cell type with UIView (both for photo/video). And I'm adding layers of AVPlayer and UIImageView on this UIView. It works, but I think it is a bad way of how this can be done. Also It's pretty bad logic with layers.

How to do it properly? Should I have 2 custom cell types? Or maybe some library exists for it?

2) I'm downloading data from Firebase-storage. This operations are async. So I'm storing MediaAspectRatio of media (width/height) in my PostItem. I'm using it to scale UIView before cell appears to not crop media. I'm also not sure, that it is correct logic.

Any suggestions are appreciated. Thanks.

解决方案

Both ways will work. However having 2 different cell types might be a cleaner implementation.

Also having 2 cell types will save you from having to swap the imageView with the AvPlayer layers on the fly, which might complicate things because of cell reuse.

As for the resizing you do, just make sure you don't break any constraints, the logic sounds good.

Image views and AvPlayers have the notion of AspectFill, that is what you want to do to not break the aspect ration of your media and not crop it at the same time.

AspectFit on the other hand will keep the Aspect Ratio and crop.

这篇关于在UITableViewCell中的UIImageView或AVPlayer(照片或视频)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆