Wednesday, December 28, 2022
HomeiOS Developmentios - Take away shadow of the UIDragPreview whereas merchandise dragging

ios – Take away shadow of the UIDragPreview whereas merchandise dragging


I’ve a UICollectionView primarily based part, when consumer dragging some cells, shadows seems and I wish to disguise it.

enter image description here

I attempted many options like this => https://stackoverflow.com/a/62046863/1705700
however no end result. Right here is my code;

func collectionView(_ collectionView: UICollectionView, itemsForBeginning session: UIDragSession, at indexPath: IndexPath) -> [UIDragItem] {
        let merchandise = self.itemList[indexPath.row]
        var dragItem: UIDragItem!
        if let path = merchandise.icon {
            let itemProvider = NSItemProvider(object: path as NSString)
            dragItem = UIDragItem(itemProvider: itemProvider)
            dragItem.localObject = merchandise
            
            dragItem.previewProvider  = { () -> UIDragPreview? in
                let previewImageView = UIImageView(picture: UIImage(named: "check"))
                previewImageView.body =  CGRect(x: 0, y: 0, width: 90, peak: 90)
                
                let dragPreview = UIDragPreview(view: previewImageView)
                return dragPreview
            }
        }
        
        return [dragItem]
    }
    
func collectionView(_ collectionView: UICollectionView, dragPreviewParametersForItemAt indexPath: IndexPath) -> UIDragPreviewParameters? {
        let previewParameters = UIDragPreviewParameters()
        previewParameters.backgroundColor = .clear
        if #out there(iOS 14.0, *) {
            previewParameters.shadowPath = UIBezierPath(rect: .zero)
        }
                
        return previewParameters
    }



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments