I'm using UICollectionView
to generate a image gallery.I used UIImage
inside the UICollectionView
Cell to load the images.I need to select UICollectionView
Cell by Long Press (not by single tap).
- (IBAction)longPress:(UILongPressGestureRecognizer *)gestureRecognizer
{
UICollectionViewCell *cell=(UICollectionViewCell *)[gestureRecognizer view];
int index=cell.tag;
OverlayImage = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, cell.frame.size.width, cell.frame.size.height)];
OverlayImage.image = [UIImage imageNamed:@"[email protected]"];
[cell addSubview:OverlayImage];
}
updated answer of it
{
let longPressGR = UILongPressGestureRecognizer(target: self, action: #selector(handleLongPress(longPressGR:)))
longPressGR.minimumPressDuration = 0.5
longPressGR.delaysTouchesBegan = true
self.collectionView.addGestureRecognizer(longPressGR)
}
@objc
func handleLongPress(longPressGR: UILongPressGestureRecognizer) {
if longPressGR.state != .ended {
return
}
let point = longPressGR.location(in: self.collectionView)
let indexPath = self.collectionView.indexPathForItem(at: point)
if let indexPath = indexPath {
var cell = self.collectionView.cellForItem(at: indexPath)
print(indexPath.row)
} else {
print("Could not find index path")
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With