0

I add long press gesture in the collectionView, but when I long pressed the item of the collectionView and swipe (my finger didn't leave the screen, I long press and after I swiped), my app crash.

Here is my longPressed code:

@objc func handleLongPress(longPressGR: UILongPressGestureRecognizer)     {
    let point = longPressGR.location(in: self.bottomCollectionView)
    let indexPath = self.bottomCollectionView.indexPathForItem(at: point)
    let notificationFeedbackGenerator = UINotificationFeedbackGenerator()
    notificationFeedbackGenerator.prepare()


    if indexPath != [0,allTimerList.timerList.count]{

    let cell = self.bottomCollectionView.cellForItem(at: indexPath!) as! BottomCollectionViewCell
    if longPressGR.state == .began {
            notificationFeedbackGenerator.notificationOccurred(.success)
            cell.transform =  CGAffineTransform(scaleX: 0.95, y: 0.95)
            cell.backgroundColor = UIColor.init(red: 255/255, green: 255/255, blue: 255/255, alpha: 0.2)

        } else {
            cell.transform =  CGAffineTransform(scaleX: 1, y: 1)
            cell.backgroundColor = UIColor.clear
            print("jies")
        }

and Xcode said the error caused by:

let cell = self.bottomCollectionView.cellForItem(at: indexPath!) as! BottomCollectionViewCell
iPeter
  • 1,330
  • 10
  • 26

0 Answers0