最近,我正在尝试做一些练习项目.所以我看了"开发iOS应用程序"课程,斯坦福大学,CS193P,2017.
现在,我正在做"Smashtag"项目,但我遇到了一些问题.我想使用带有两个UICollectionViewFlowLayout的CollectionView,通过SegmentedControl在每个xib中显示两个类型(一个像tableView,另一个在方块中显示图像).
我的问题如下:
如何使CollectionViewCell显示在动态高度,就像TableView的UITableViewAutomaticDimension一样?
这就是我刚刚尝试过的内容:
我尝试使用UICollectionViewFlowLayoutAutomaticSize使CollectionView的autoResize设置像TableView的autoDimension 一样.(@available(iOS 10.0,*))
enum CollectionViewType {
case tweet
case image
}
// MARK: - Decide What Kind Of FlowLayout
func decideFlowLayout(type: CollectionViewType) -> UICollectionViewFlowLayout {
// just for .image type
var howManyImageShowing = 3
var imageShowingWidth: Double {
return Double(self.view.frame.width) / Double(howManyImageShowing)
}
// .tweet is a type showing like TableViewCell -> this make me confused !!
// another type is just showing a image in square -> I have no problem here …Run Code Online (Sandbox Code Playgroud)