Swift 使用下拉菜单查看集合 < >我希望创建一个下拉菜单,该菜单只出现在“空”选项卡被选中的地方,当选中“最新”选项卡时,它仍然隐藏。p>
我如何做到这一点 viewController图像: 我必须为此使用Swift 使用下拉菜单查看集合 < >我希望创建一个下拉菜单,该菜单只出现在“空”选项卡被选中的地方,当选中“最新”选项卡时,它仍然隐藏。p>,swift,uicollectionview,Swift,Uicollectionview,我如何做到这一点 viewController图像: 我必须为此使用uisearchdelegate 编辑:如何使CollectionView的headerView响应顶部的分段控制按钮:“最新和季节性”?例如,当选择“最新”时,标题视图将调整为宽度:0,高度:0;当选择“季节”时,标题将调整为宽度:320,高度:50 这里有一个例子,但到目前为止我的代码是错误的。我不知道如何返回CGSize func collectionView(collectionView: UICollectionVi
uisearchdelegate
编辑:如何使CollectionView的headerView响应顶部的分段控制按钮:“最新和季节性”?例如,当选择“最新”时,标题视图将调整为宽度:0,高度:0;当选择“季节”时,标题将调整为宽度:320,高度:50
这里有一个例子,但到目前为止我的代码是错误的。我不知道如何返回CGSize
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize {
if segmentedControlValue.selectedSegmentIndex == 1 {
let size = CGSize (width: 0, height: 50)
}
if segmentedControlValue.selectedSegmentIndex == 0 {
let size = CGSize (width: 0, height: 0)
}
}
@IBAction func selectionButtons(_ sender: UISegmentedControl) {
collectionView?.reloadData()
}
以下是我刚刚添加的新代码:
override func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
let selectionCell = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "selectionCell", for: indexPath)
if toggleState.currentTitle == "View" {
selectionCell.frame = CGRect(x: 0, y: 0, width: 0, height: 100)
}
if toggleState.currentTitle == "NoView" {
selectionCell.frame = CGRect(x: 0, y: 0, width: 0, height: 0)
}
return selectionCell
您可以使用
collectionView
ViewforSupplementalElementofKind
方法处理带有UICollectionElementKindSectionHeader
的页眉和带有UICollectionElementKindSectionFooter
kind视图的页脚
func collectionView(collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, atIndexPath indexPath: NSIndexPath) -> UICollectionReusableView {
let view = collectionView.dequeueReusableSupplementaryViewOfKind(UICollectionElementKindSectionHeader, withReuseIdentifier: "myHeaderView", forIndexPath: indexPath)
// configure header view
if segmentedControlValue.selectedSegmentIndex == 1 {
view.frame = // set frame
}
if segmentedControlValue.selectedSegmentIndex == 0 {
view.frame = // set frame
}
return view
}
因此,当您调用
reloadData()
方法时,这将作为执行的一部分,您可以采取适当的操作来查看内部的view
。无法正确获取您的问题?好的,我已经用代码对其进行了更新。是否将其作为免费使用uiview的collectionView的一部分?免费使用UI view。如果可能的话,我想制作一个粘性标题,当你点击设置时,它会下降,允许你在重新加载集合视图之前编辑要解析的数据的过滤器。这就是本文的要点。检查我的ans并让我知道你的反馈。不,仍然不起作用,我已经编辑了我的文章,加入了我刚才添加的代码。@Lerws有一些小错误,你可以看到。。只需添加UICollectionElementKindSectionHeader
作为suppview,并将宽度设置为320或动态,如果条件允许,则首先将该视图的高度设置为100,以便视图可见或准确使用我的代码。在使用我的代码时,请评论您的collectionViewLayout
方法,您几乎完成了。