我有一个全屏水平collectionview。如何将手势识别器添加到collectionview单元格中的uiview中
- 滚动禁用
- 分页被启用,也有对未来分页/分组按钮。
在我的collectionview cell中,我有一个标签,当用户向左/向右滑动时,我想识别它。 我将标记添加到标签后没有任何反应。
CODE:
collectionViewCell:
func addGesture(){
let right = UISwipeGestureRecognizer(target: myLabel, action: "test")
right.direction = UISwipeGestureRecognizerDirection.Left
answer.addGestureRecognizer(right)
}
视图控制器:
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("formQuestionCell", forIndexPath: indexPath) as QuestionCell
cell.addGesture()
return cell
}
我也尝试从myLabel切换目标自我,它仍然无法正常工作。
感谢
谢谢, 我得到一个无法识别的选择器发送到实例。 – ilan
您是否在视图控制器中实现了'test:'?你需要否则你会得到这样的错误。无论您设置了“目标”,都必须实现该选择器。 – trevorj
效果很好,忘了补充:去测试。 – ilan