在表格视图单元格内设置集合视图约束的正确方法 [英] Proper way to set constraints of collection view inside of table view cell

查看:55
本文介绍了在表格视图单元格内设置集合视图约束的正确方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道对此设置约束的正确方法.我在表视图单元格中有一个集合视图,作为在用户发布的图像之间滑动的一种方式.每个帖子(tableview 单元格)可以包含多个图像(每个图像都发布在集合视图中).我要使用与 instagram 类似的风格,您可以在其中滑动图像.我遇到的问题是当我对集合视图和图像视图设置约束时,它们不会在设备之间改变.似乎唯一的方法是根据用户使用的设备手动更改集合视图单元格和图像视图的大小.任何实现我想要完成的外观的替代方法也将不胜感激.

I am wondering the proper way to set the constraints on this. I have a collection view inside of a table view cell as a way to swipe between images that the user posts. Each post (tableview cell) can contain multiple images (Which are each posted in the collection view). I am going for a similar style as instagram has where you can swipe between images. The problem I am having is when I set constraints on the collection view and image view they don't change between devices. It seems the only way to do it is manually change the size of the collection view cell and image view depending on the device the user is using. Any alternative way to achieve the look I am trying to accomplish would be appreciated as well.

这是对集合视图设置的约束

Here are the constraints set on the collection view

这是帖子在 iPhone SE 上的显示效果

Here is how the post looks on an iPhone SE

以下是该帖子在 iPhone 8 Plus 上的外观

Here is how the post is supposed to look on the iPhone 8 Plus

界面构建器中故事板上的整体帖子.

Overall post on the storyboard in interface builder.

这是在图像上设置的约束,它位于集合视图中.

Here are the constraints set on the image, which is inside the collection view.

推荐答案

我很感激答案,我解决问题的方法是使用此代码更改集合视图单元格的大小

I appreciate the answer, the way I solved the problem was by changing the size of the collection view cell using this code

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) ->CG尺寸{返回CGSize(宽度:UIScreen.main.bounds.width,高度:346)}

我意识到图像约束是针对单元格的,并且无法对单元格本身设置约束,因此您需要更改单元格的大小,使图像放大或缩小.

I realized the image constraints were to the cell and there is no way to set constraints on the cell itself, so you need to change the size of the cell so the image becomes enlarged or shrinks.

这篇关于在表格视图单元格内设置集合视图约束的正确方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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