长按和滑动使我的应用程序崩溃

时间:2018-06-19 08:46:35

标签: ios swift uigesturerecognizer collectionview

我在collectionView中添加了长按手势,但是当我长按了collectionView的项目并轻扫(我的手指没有离开屏幕,我长按并且在我刷完后),我的应用程序崩溃了。 / p>

这是我的longPressed代码:

@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")
        }

和Xcode表示由以下原因引起的错误:

let cell = self.bottomCollectionView.cellForItem(at: indexPath!) as! BottomCollectionViewCell

0 个答案:

没有答案