What is the best strategy for this?


Rick Aurbach
 

Problem: I am designing a collection view with overlapping cells. Each cell has an active area inside it (and the active areas of adjacent cells do not overlap). (More information about what I'm doing at the bottom of this post.) I want a tap in the active area of a cell to select that cell, but a tap outside the active area of any cell should deselect the currently selected cell [single selection only; I don't need to support multi-selection at this point].

My original thought was to override the collection view's indexPathForItem(at:) and either the cell's touch event handlers or UICollectionView's touch event handlers. But, to make this work, I also need to know something about HOW the touch event handler interact with the UICollectionView. (This might be as simple as having touchesEnded(_:with:) call selectItem(at:animated:scrollPosition:) and deselectItem(at:animated:). Or?)

Before I start possibly reinventing the wheel here, I'd like to ask if anyone has done anything similar and has any ideas to share.

Thanks,

Rick

-------------------------
Consider a square cell which contains a diamond. The four vertices of the diamond are the midpoints of the four sides of the cell. The active region of each cell is the area inside the diamond. Cells are close-packed horizontally. Each section (i.e., "row") is offset a half-width down and a half-width to the side of the cells above it. In other words, the cells are positioned so that the diamond edges are superimposed. The attached image should give you an idea.

Join cocoa@apple-dev.groups.io to automatically receive all group messages.