Ios 禁用uicollectionview水平滚动的外部平移手势

Ios 禁用uicollectionview水平滚动的外部平移手势,ios,iphone,swift,uicollectionview,uipangesturerecognizer,Ios,Iphone,Swift,Uicollectionview,Uipangesturerecognizer,在我的viewController中,我有一个CollectionView:mainCollectionView作为UIView子视图,其中有三个单元格(viewController帧大小)可以水平滚动。mainCollectionView还有一个panGesture,显示另一个视图控制器:sideMenuController 在mymainCollectionView单元格中,另一个水平滚动的collectionView:weekCollectionView作为子视图。当im在weekColl

在我的viewController中,我有一个CollectionView:
mainCollectionView
作为UIView子视图,其中有三个单元格(viewController帧大小)可以水平滚动。
mainCollectionView
还有一个
panGesture
,显示另一个视图控制器:
sideMenuController

在my
mainCollectionView
单元格中,另一个水平滚动的collectionView:
weekCollectionView
作为子视图。当im在
weekCollectionView
中滚动时,如何禁用
PangTesture
mainCollectionView
滚动

这是我的密码-

mainCollectionView Pangestree:

fileprivate func setupPanGesture() {
        panGesture = UIPanGestureRecognizer(target: self, action: #selector(panRight(sender:)))
        panGesture.delegate = self
        mainCollectionView.addGestureRecognizer(panGesture)
    }

@objc func panRight(sender: UIPanGestureRecognizer) {
    let translation = sender.translation(in: mainCollectionView)
    let indexPath = NSIndexPath(item: 0, section: 0)
    if (mainCollectionView.cellForItem(at: indexPath as IndexPath) != nil) {
        if translation.x > 0 {
            (UIApplication.shared.keyWindow?.rootViewController as? MasterViewController)?.handlePan(sender: sender)
            mainCollectionView.isScrollEnabled = false
        } else if translation.y > 0 || translation.y < 0 {
            panGesture.isEnabled = false
            mainCollectionView.isScrollEnabled = true
        }
    }
    if (mainCollectionView.cellForItem(at: indexPath as IndexPath) == nil) {
        panGesture.isEnabled = false
        mainCollectionView.isScrollEnabled = true
    }
    panGesture.isEnabled = true
    mainCollectionView.isScrollEnabled = true
}

func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {
    return true
}
fileprivate func setupPanGesture(){
panGesture=UIPangESTURE识别器(目标:自我,操作:#选择器(右窗格(发送方:))
panGesture.delegate=self
mainCollectionView.AddGestureRecognitor(panGesture)
}
@objc func panRight(发送方:UIPangestureRecognitor){
让translation=sender.translation(在:mainCollectionView中)
让indexPath=NSIndexPath(项:0,节:0)
if(mainCollectionView.cellForItem(at:indexPath as indexPath)!=nil){
如果translation.x>0{
(UIApplication.shared.keyWindow?.rootViewController作为?MasterViewController)?.handlePan(发送方:发送方)
mainCollectionView.IsCrollenabled=false
}否则,如果translation.y>0 | | translation.y<0{
panGesture.isEnabled=false
mainCollectionView.IsCrollenabled=true
}
}
if(mainCollectionView.cellForItem(at:indexPath as indexPath)==nil){
panGesture.isEnabled=false
mainCollectionView.IsCrollenabled=true
}
panGesture.isEnabled=true
mainCollectionView.IsCrollenabled=true
}
func gestureRecognizer(uGestureRecognizer:UIGestureRecognizer,应与其他gestureRecognizer:UIGestureRecognizer同时识别)->Bool{
返回真值
}

为类实现UIgestureRecognitizerDelegate

将手势委托设置为self

panGesture.delegate = self
添加此委托函数

func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {
    if (gestureRecognizer is UIPanGestureRecognizer || gestureRecognizer is UIRotationGestureRecognizer) {
        return true
    } else {
        return false
    }
}