在UICollectionView中长按和平移手势

时间:2016-06-21 06:40:02

标签: ios objective-c iphone uicollectionview uigesturerecognizer

我正在处理从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方法。我是手势概念的新手。拖动收集视图时,它没有调用该方法。

这可能是什么问题?谁能指导我这个?

如果我处理的方式有误,我们将非常感谢新的建议。

2 个答案:

答案 0 :(得分:1)

据我所知,集合视图没有类似于表视图的编辑模式。幸运的是,someone has already solved this problem for you

答案 1 :(得分:1)

panGestureRecognizer有自己的pinchGestureRecognizer-(void)scrollViewDidScroll:(UIScrollView *)scrollView; 。所以它没有必要添加。我建议你在其委托功能中获得触摸事件。这是其中之一:

ServerManager serverMgr = new ServerManager();
Site site = serverMgr.Sites["YourSiteName"];
List<string[]> urls = new List<string[]>();
foreach (Binding binding in site.Bindings)
{
    string bindingInfo = binding.BindingInformation;
    string subString = bindingInfo.Substring(2, bindingInfo.Length - 2);
    string[] adrs = subString.Split(':');
    adrs[0] = "localhost:" + adrs[0];
    urls.Add(adrs);
}