简体   繁体   中英

Customizing collection views and creating space between the collection view’s cells

I'm trying to create this relationship that the pictures below depict of Parent -> Children -> Children -> etc. . . I'm trying to use a vertical collection view for the Parent collection view and then nested horizontal collection views for the children. But I'm struggling with moving the collection views cells down when the “View Children Button” is clicked. I thought I could do something like this when the button is clicked:

@IBAction func showChildrenBtnClicked(_ sender: Any) {

    collectionView.contentInset.bottom = 200
    collectionView.reloadData()

}

but this doesn't seem to do anything. Does anyone know how to add empty space inside the collection view so that I could then create a horizontal collection view to hold the children elements.

These are some mock images of the behavior I'm trying to achieve:

Step 1) 在此处输入图片说明

Step 2) 在此处输入图片说明

Step 3) 在此处输入图片说明

Step 4) 在此处输入图片说明

Step 5) 在此处输入图片说明

Thank you in advance.

First take all the view as collection view. When ViewchildrenButton get tapped, delegate it to the parent collection view controller class, and there

if let flowLayout = metaMoreCollectionView.collectionViewLayout as? UICollectionViewFlowLayout {
        flowLayout.invalidateLayout()
    }

This will call the

collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize

and give the updated size there.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM