Search code examples
iosswiftuicollectionviewcosmicmind

Material Ripple Effect for UICollectionView Cell


I am trying to create a material ripple effect for a UICollectioView cell. For Android, there are several material design options to do so, but for iOS that does not appear to be the case. Below is my custom cell I am using as the prototype to populate the UICollectioView:

import UIKit

class PollCell: UICollectionViewCell {


    @IBOutlet weak var imageView: UIImageView!

    @IBOutlet weak var pollQuestion: UILabel!

}

Where I initialize the CollectioViewCell:

    override func viewDidLoad() {
    super.viewDidLoad()

    ref = FIRDatabase.database().reference()
    prepareMenuButton()


    // Uncomment the following line to preserve selection between presentations
    // self.clearsSelectionOnViewWillAppear = false

    // Register cell classes

    self.dataSource = self.collectionView?.bind(to: self.ref.child("Polls")) { collectionView, indexPath, snap in
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath) as! PollCell
        //Here is where I am having issues
        cell.pulseAnimation
        /* populate cell */
        cell.pollQuestion.text = snap.childSnapshot(forPath: "question").value as! String?
        let urlPollImage = snap.childSnapshot(forPath: "image_URL").value as! String?

        cell.imageView.sd_setImage(with: URL(string: urlPollImage!), placeholderImage: UIImage(named: "Fan_Polls_Logo.png"))
        //Comment
        return cell
    }

Here is an image of one of the cells on a device:

enter image description here


Solution

  • If you use Material it has a CollectionViewCell that has the pulse animation built in. You can set it with the pulseAnimation property. Hope this helps.