【问题标题】:Long press and pan gesture in UICollectionViewUICollectionView 中的长按和平移手势
【发布时间】:2016-06-21 06:40:02
【问题描述】:

我正在处理从GitHub 下载的自定义日历。这是一个自定义视图,其中添加了 UICollectionView 以显示日期单元格。我正在添加一个拖动单元格以获取多个日期值的功能。为此,我添加了 UILongpressgesture

我已经尝试过,

@property (nonatomic, strong) UILongPressGestureRecognizer *dragDateGesture;

 self.dragDateGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleDragBeginDate:)];
 self.dragDateGesture.delegate = self;
 self.dragDateGesture.minimumPressDuration = 0.05;
 [self.collectionView addGestureRecognizer:self.dragDateGesture];

- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)recognizer
{
return YES;
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{
return YES;
}
- (void)handleDragBeginDate:(UIPanGestureRecognizer *)recognizer
{
 NSLog(@"Gesture recognised");
}

在上面的代码中,我添加了长按手势并将同步手势识别器设置为是。我不确定,添加长按手势是否会使用 UIPanGestureRecognizer getter 调用 handleDragBeginDate 方法。我是手势概念的新手。拖动collectionview时不会调用该方法。

这可能是什么问题?有人可以指导我吗?

如果我的方法有误,我们将不胜感激新的建议。

【问题讨论】:

  • 你想在日历中做什么

标签: ios objective-c iphone uicollectionview uigesturerecognizer


【解决方案1】:

据我所知,collection view 没有类似于 table view 的编辑模式。幸运的是,someone has already solved this problem for you

【讨论】:

  • 感谢您的回复,我找到了一个带有拖动选项的自定义日历,github.com/Glow-Inc/GLCalendarView。它在模拟器中工作。但我无法将这些代码移动到我的自定义日历...
  • @NAZIK 是什么阻止你这样做?
  • 我找到了解决方案,我没有在自定义视图中添加 UILongPressGestureRecognizer,而是在 viewcontroller 中添加并向 collectionview 添加手势,它现在可以工作了,感谢您的建议
【解决方案2】:

UICollectionView 有自己的panGestureRecognizerpinchGestureRecognizer。所以不需要添加。我建议您在其委托函数中获取触摸事件。这是其中之一:

-(void)scrollViewDidScroll:(UIScrollView *)scrollView;

【讨论】:

    猜你喜欢
    • 2015-08-07
    • 2021-11-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-25
    • 2014-07-09
    相关资源
    最近更新 更多