Add a collectionview into a view Add the view into a
backgroundview(UIView)
- Add tapGestureRecognizer to the backgroundView
The select event of collectionview can not be triggered when tap a cell,It always trigger the tap event of backgroundview
let backgroundView = UIView(frame: sender.window!.bounds)
backgroundView.backgroundColor = UIColor.yellowColor()
let blueView = BlueView(frame: CGRect(x: 300, y: 200, width: 300, height: 400))
backgroundView.addSubview(blueView)
sender.window!.addSubview(backgroundView)
backgroundView.userInteractionEnabled = true
let gesture = UITapGestureRecognizer(target: blueView, action: "tapGestureRecognizer")
gesture.delegate = blueView
backgroundView.addGestureRecognizer(gesture)
..........
let cv = UICollectionView(frame: CGRect(x: 100, y: 0, width: 100, height: 340), collectionViewLayout: layout)
cv.registerClass(UICollectionViewCell.self, forCellWithReuseIdentifier: "cell")
cv.dataSource = self
blueView.addSubview(cv)
Who know the reason?