Ios 手势识别器不';t在其他UICollectionViewCell内部处理UICollectionView
我创建了一个UICollectionView作为主UICollectionView,每个collectionViewCell都有另一个UICollectionView“B”作为其子视图 然后我在“B”中加上一个轻拍手势。但是“B”不能触发这个手势。 以下是我的主要代码: 主UICollectionViewIos 手势识别器不';t在其他UICollectionViewCell内部处理UICollectionView,ios,swift,uicollectionview,Ios,Swift,Uicollectionview,我创建了一个UICollectionView作为主UICollectionView,每个collectionViewCell都有另一个UICollectionView“B”作为其子视图 然后我在“B”中加上一个轻拍手势。但是“B”不能触发这个手势。 以下是我的主要代码: 主UICollectionView import Foundation import UIKit class mainViewController :UIViewController,UICollectionViewDataS
import Foundation
import UIKit
class mainViewController :UIViewController,UICollectionViewDataSource,UICollectionViewDelegate {
@IBOutlet weak var mainCollectionView: UICollectionView!
override func viewDidLoad() {
self.mainCollectionView.registerNib(UINib(nibName: "OuterCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "OuterCollectionViewCell")
self.mainCollectionView.delegate = self
self.mainCollectionView.dataSource = self
}
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int
{
return 1
}
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell
{
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("OuterCollectionViewCell", forIndexPath: indexPath) as! OuterCollectionViewCell
return cell
}
}
UICollectionView B:
class OuterCollectionViewCell: UICollectionViewCell,UICollectionViewDataSource, UICollectionViewDelegate {
@IBOutlet weak var InnerCollectionView: UICollectionView!
override func awakeFromNib() {
super.awakeFromNib()
InnerCollectionView.registerNib(UINib(nibName: "InnerCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "CellInner")
}
func handleTapGesture(sender: UITapGestureRecognizer) {
print("tapguesture")
}
override func didMoveToWindow(){
let tapGesture = UITapGestureRecognizer(target: self, action: "handleTapGesture:")
InnerCollectionView.backgroundColor = UIColor.redColor()
InnerCollectionView.addGestureRecognizer(tapGesture)
InnerCollectionView.delegate = self
InnerCollectionView.dataSource = self
}
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 1
}
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("CellInner", forIndexPath: indexPath) as! InnerCollectionViewCell
return cell
}
}
这个问题困扰了我一整天。有没有人对如何解决这个问题有任何想法
我已将项目上载到github:
更新
今天,我通过可编程的代码初始化innerCollectionView,而不是通过NIB初始化。它是有效的
let flowLayout = UICollectionViewFlowLayout()
flowLayout.scrollDirection = UICollectionViewScrollDirection.Horizontal
let InnerCollectionView = UICollectionView(frame: CGRect(x: 0, y: 0, width: 800, height: 600), collectionViewLayout: flowLayout)
我不知道笔尖对UIcollectionview做了什么
我确实在界面生成器中将userInteractive设置为true是您的
InnerCollectionView。UserInteractiveEnable
设置为true
?是设置为true无影响