Search code examples
iosswiftuicollectionviewviewcontroller

how to hide uicollectionview on a ViewController using swift


I have a simple ViewController which has a 2 buttons names "Files" and "Folders". Also i have placed two uiCollectionView.

When I tap "Files" button it should hide one of the uiCollectionView at runtime and when I tap "Folders" it should do same for other uiCollectionView. Is there any property or method to achieve the same.

how can i do this using swift ?

thanks


Solution

  • To hide:

    collectionView.hidden = true
    

    To show:

    collectionView.hidden = false
    

    If you want to animate this, you can fade in and fade out.

    Fade out:

    self.collectionView.alpa = 1
    UIView.animateWithDuration(1, {
        self.collectionView.alpha = 0
    })
    

    Fade in:

    self.collectionView.alpa = 0
    UIView.animateWithDuration(1, {
        self.collectionView.alpha = 1
    })