Ios 是否在CollectionView中未禁用滚动视图?

Ios 是否在CollectionView中未禁用滚动视图?,ios,swift,scrollview,collectionview,Ios,Swift,Scrollview,Collectionview,我是swift新手,我正在尝试在collectionView中实现一个功能(这是滚动启用。默认情况下,我希望启用滚动并禁用pangesturerecgonizer。但在识别长按后,滚动将被禁用,并启用平移手势。完成平移手势后,应禁用滚动并启用滚动。我有以下代码 lazy var panGesture: UIPanGestureRecognizer = { let pan = UIPanGestureRecognizer(target: self, action: #selector(s

我是swift新手,我正在尝试在collectionView中实现一个功能(这是滚动启用。默认情况下,我希望启用滚动并禁用pangesturerecgonizer。但在识别长按后,滚动将被禁用,并启用平移手势。完成平移手势后,应禁用滚动并启用滚动。我有以下代码

lazy var panGesture: UIPanGestureRecognizer = {
    let pan =  UIPanGestureRecognizer(target: self, action: #selector(self.handlePan(sender:)))
        pan.delegate = self
    return pan
}()

override func viewDidLoad() {
    super.viewDidLoad()

    collectionView.delegate = self
    collectionView.dataSource = self
    collectionView.backgroundColor = UIColor.cyan
    self.view.addSubview(collectionView)

    self.view.addConstraint(NSLayoutConstraint(item: collectionView, attribute: .height, relatedBy: .equal, toItem: self.view, attribute: .height, multiplier: 1.0, constant: 0.0))

    collectionView.translatesAutoresizingMaskIntoConstraints = false
    collectionView.leftAnchor.constraint(equalTo: view.leftAnchor).isActive = true
    collectionView.rightAnchor.constraint(equalTo: view.rightAnchor).isActive = true
    collectionView.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true
    collectionView.addGestureRecognizer(panGesture)
    panGesture.isEnabled = false

    let tap = UILongPressGestureRecognizer(target: self, action: #selector(self.handleTap(sender:)))
    tap.delegate = self
    collectionView.addGestureRecognizer(tap)

}

func handlePan(sender: UIPanGestureRecognizer? = nil) {
    var locationOfBeganTap: CGPoint?

    if sender?.state == .possible { 
    }

    if sender?.state == .ended {
        startTime = NSDate.timeIntervalSinceReferenceDate
    }
}

func handleTap(sender: UIPanGestureRecognizer? = nil){            
    if sender?.state == .began {
        panGesture.isEnabled = true
        self.collectionView!.isScrollEnabled = false
    }

    if sender?.state == .ended {
    }
}

谢谢!

我不明白,你是说当平移被触发时,卷轴不能被禁用,平移不再工作了

尝试添加滚动视图的用户交互:

collectionV.isScrollEnabled = false
collectionV.isUserInteractionEnabled = true
你可以申请


collectionView.isUserInteractionEnabled=true

collectionView.isUserInteractionEnabled已经为true。也许我的编辑更有意义。