Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
559 views
in Technique[技术] by (71.8m points)

ios - Swift: How to properly reuse a UICollectionViewCell's CALayerMask property in a UICollectionView

I set my cell's, cell.customView.layer.mask property in the following function:

func collectionView(_ collectionView: UICollectionView, willDisplay cell: UICollectionViewCell, forItemAt indexPath: IndexPath)

I also set the property after I call collectionView.dequeueReusableCell.

However, I noticed the cell.customView.layer.mask gets all messed up when the cell is recycled and reused, as different cells have the wrong mask applied to them.

How can I properly reuse the mask property in my UICollectionViewCell class?

EDIT: More question details

Here, I will describe my specific use case/problem.

I have found this random image from Google Images of the Facebook Messenger Chat:

enter image description here

Notice how each of the message bubbles (which I will refer to as cells) have different corner radii? The first bubble has its bottom right-hand corner rounded much less than the other corners, etc, etc?

Originally, I was setting the type of corner radius I want by applying a UIBezierPath mask to each cell in collectionView.dequeueReusableCell and the willDisplayCell function, however, from the comments, it seems it would be better to create unique cells, and just dequeue the cell I want that has the correct mask/corner radius, instead of constantly changing/updating different masks?

What are everyone's thoughts? Thank you for your time and understanding, I am new to stack overflow :)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...