Search
 
SCRIPT & CODE EXAMPLE
 

SWIFT

how to get index path cell collection view from ui longpress gesture swift

private func setupLongGestureRecognizerOnCollection() {
    let longPressedGesture = UILongPressGestureRecognizer(target: self, action: #selector(handleLongPress(gestureRecognizer:)))
    longPressedGesture.minimumPressDuration = 0.5
    longPressedGesture.delegate = self
    longPressedGesture.delaysTouchesBegan = true
    collectionView?.addGestureRecognizer(longPressedGesture)
}

@objc func handleLongPress(gestureRecognizer: UILongPressGestureRecognizer) {
    if (gestureRecognizer.state != .began) {
        return
    }

    let p = gestureRecognizer.location(in: collectionView)

    if let indexPath = collectionView?.indexPathForItem(at: p) {
        print("Long press at item: (indexPath.row)")
    }
}
Comment

PREVIOUS NEXT
Code Example
Swift :: timer functionality in swift stack overflow 
Swift :: play sound in swift 5 
Swift :: Check if device is iPhone or not swift ios 
Swift :: swift remove space from string 
Swift :: swiftui checkbox 
Swift :: swift open web page 
Swift :: swift add button to container 
Swift :: increase the size of the image in Swiftui 
Swift :: swiftui text alignment 
Swift :: change selection color uitableviewcell swift 
Swift :: pop the view controller xcode 
Swift :: array length swift 
Swift :: swift get max of two numbers 
Swift :: how to convert int to double in swiftui 
Swift :: hide status bar in tableview cell in swift 
Swift :: power number in swift13 
Swift :: how to call app delegate function in swift 
Swift :: convert dictionary to array swift 
Swift :: swift uitableview insert cell 
Swift :: swift map array to dictionary 
Swift :: enviroment dissmiss swiftui 
Swift :: imageliteral swiftui 
Swift :: switch button swift 5 
Swift :: swift paged scrollview get current page 
Swift :: swift extension Array with element 
Swift :: swift resource exceeds maximum size 
Swift :: two variable sum 
Swift :: swift combine 2 sets 
Swift :: Swift n Parameter with Default Values 
Swift :: swift check if array has duplicates 
ADD CONTENT
Topic
Content
Source link
Name
3+8 =