-
Hi, I have context menu in my app, but when they are displayed, the messagesCollectionView Cell's background is not blurred out as with the rest of the collection view (see attached image). How do I blur the cell out and only leave the bubble message displayed? Here is my code: func collectionView(_ collectionView: UICollectionView, contextMenuConfigurationForItemAt indexPath: IndexPath, point: CGPoint) -> UIContextMenuConfiguration? {
Thank you. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
For those who would like a solution in the future, here: NOTE: in your context menu configuration set identifier as so: func collectionView(_ collectionView: UICollectionView, previewForHighlightingContextMenuWithConfiguration configuration: UIContextMenuConfiguration) -> UITargetedPreview? {
return makeTargetedPreview(for: configuration)
}
func collectionView(_ collectionView: UICollectionView, previewForDismissingContextMenuWithConfiguration configuration: UIContextMenuConfiguration) -> UITargetedPreview? {
return makeTargetedPreview(for: configuration)
}
private func makeTargetedPreview(for configuration: UIContextMenuConfiguration) -> UITargetedPreview? {
guard let indexPath = configuration.identifier as? IndexPath else { return nil }
// Get the cell for the index of the model
guard let selectedCell = messagesCollectionView.cellForItem(at: indexPath) as? MessageContentCell else { return nil }
let parameters = UIPreviewParameters()
parameters.backgroundColor = .clear
// Return a targeted preview using our cell previewView and parameters
return UITargetedPreview(view: selectedCell.messageContainerView, parameters: parameters)
} |
Beta Was this translation helpful? Give feedback.
For those who would like a solution in the future, here:
NOTE: in your context menu configuration set identifier as so:
let config = UIContextMenuConfiguration(identifier: indexPath as NSCopying, previewProvider: nil)