【发布时间】:2017-01-22 04:12:54
【问题描述】:
我是 iOS 开发的新手,正在尝试创建一个 PokeDex 应用程序。我的主视图控制器有一个集合视图,它返回两种类型的自定义单元格。我的第一个称为选择器单元格的单元格位于导航栏或标题栏的下方,无论哪个术语,我希望我的第二个自定义单元格(描述单元格)位于选择器单元格的下方并占据整个屏幕。我最初将描述单元格的高度设置为视图的高度 - 50 以考虑选择器单元格,但我看到剩余的一些空间显示了集合视图的颜色。然后我决定将 descriptionview 设为整个 view.frame 的高度,但由于某种原因仍有空白空间。它不是很多空间,通过使集合视图与我的描述单元颜色相同,一切看起来都很好,但为什么会发生这种情况?
视图控制器中的代码:
import UIKit
class PokeDexController: UICollectionViewController, UICollectionViewDelegateFlowLayout {
private let cellID = "cellID"
private let cellID2 = "cellID2"
override func viewDidLoad() {
super.viewDidLoad()
self.title = "PokeDex 386"
//collectionView?.backgroundColor = UIColor(red: 52/255.0, green: 55/255.0, blue: 64/255.0, alpha: 1.0)
collectionView?.backgroundColor = UIColor.white
collectionView?.register(chooserCell.self, forCellWithReuseIdentifier: cellID)
collectionView?.register(DescriptionCell.self, forCellWithReuseIdentifier: cellID2)
}
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
if (indexPath.row == 0)
{
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: cellID, for: indexPath) as! chooserCell
return cell
}
else
{
let cell2 = collectionView.dequeueReusableCell(withReuseIdentifier: cellID2, for: indexPath) as! DescriptionCell
return cell2
}
}
override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 2
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
if(indexPath.row == 0)
{
return CGSize(width: view.frame.width, height: 50)
}
else
{
return CGSize(width: view.frame.width, height: view.frame.height)
}
}
}
how the app currently looks, empty space between two cells
谢谢
【问题讨论】: