如何禁用UICollectionView上的多次触摸 [英] How to disable multiple touch on a UICollectionView

查看:452
本文介绍了如何禁用UICollectionView上的多次触摸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在UICollectionView上禁用多次触摸?

How can I disable multiple touch on a UICollectionView ?

我想同时禁用两个单元格的选择。

I want to disable the selection of two cell simultaneously.

我尝试了这个但它不起作用:

I tried this but it doesn't work :

self.collectionView.multipleTouchEnabled = NO;
self.collectionView.exclusiveTouch = YES;

谢谢。

推荐答案

第一次调用 didSelectItemAtIndexPath 后,可以将布尔标志设置为true,如果标志为false,则返回方法返回第二次调用方法)。从显示的视图返回后,您可以将标志设置为false,以便再次启用该方法的单个调用(第一个)。

You could set a Boolean flag to true after didSelectItemAtIndexPath is called for the first time and return from the method if the flag is false (for the second call to the method). After you return from your displayed view, you can set your flag back to false in order to enable a single call (the first one) to the method again.

在您的 viewDidAppear 将标记设置为FALSE(尚未触摸)

In your viewDidAppear set the flag to FALSE (no touching has been done)

然后在 didSelectItemAtIndexPath

Then in your didSelectItemAtIndexPath

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath 
{
   if(self.flag==TRUE){
       return;
   }
   // This will set the flag to TRUE the first time the method is called
   self.flag=TRUE;
   // the rest of your code: display the view
}

假设你已经在你的类中声明了一个标志实例变量。

Assuming you have already declared a flag instance variable in your class.

* Swift4代码的更新*

 func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
      if flag { return }

      // This will set the flag to TRUE the first time the method is called
      flag = true
      // the rest of your code: display the view
 }

这篇关于如何禁用UICollectionView上的多次触摸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆