【问题标题】:How to prevent second tap on UICollectionViewCell?如何防止第二次点击 UICollectionViewCell?
【发布时间】:2013-06-28 06:32:57
【问题描述】:

单元格中有UICollectionView。通过点击应该添加单元格子视图。

一切正常,但是...如果我快速点击第二次或第三次,它会添加两个或三个子视图...

那么如何正确地做到这一点呢?

这是didSelectItemAtIndexPath的代码:

recipeDetailView = [[RecipeDetailViewController alloc] initWithNibName:@"RecipeDetailViewController" bundle:nil];

[recipeDetailView.view setBackgroundColor: [UIColor colorWithPatternImage:[UIImage imageNamed:@"bgRecipe.jpg"]]];
[recipeDetailView.view setFrame: myFrame];

[UIView animateWithDuration:0.3
                      delay:0.0
                    options: UIViewAnimationOptionCurveLinear
                 animations:^{
                     [recipeDetailView.view setFrame: CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
                     [self.view addSubview:recipeDetailView.view];
                     [self addChildViewController:recipeDetailView];
                     [recipeDetailView didMoveToParentViewController:self];
                 }
                 completion:^(BOOL finished){
                     [recipeDetailView slideViewAdd];
                 }];

【问题讨论】:

  • 查看- (BOOL) collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath

标签: ios uiview uicollectionview


【解决方案1】:

didSelectItemAtIndexPath 中,只需将所有代码添加到此。

 if(recipeDetailView ==  nil)
 {

  //copy all your codes from above question.

 }

当您删除视图时,只需将 recipeDetailView 设置为 nil。

 recipeDetailView = nil;

【讨论】:

    【解决方案2】:

    在检测到点击后短时间内禁用用户交互。

    或者,使用手势识别器检测点击,另一个检测多次点击,并要求多次点击识别器在点击识别器触发之前失败。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-01-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-03
      • 1970-01-01
      相关资源
      最近更新 更多