小编cod*_*ode的帖子

当超级视图有手势时,collectionView 没有调用 didSelectItemAtIndexPath

当 superview 有 tapGesture 时,collectionView 没有调用 didSelectItemAtIndexPath?这是为什么?
为什么它根据响应者链打印“doGesture”?

  1. initCollectionView 然后添加到 self.view
  2. 在 self.view 中添加TapGesture
  3. 单击 iPhone 中的项目。
  4. 不调用 didSelectItemAtIndexPath。

    - (void)viewDidLoad {
        [super viewDidLoad];
        UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
        self.collectionView = [[MyCollectionView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height - 100) collectionViewLayout:flowLayout];
        [self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"abc"];
        self.collectionView.delegate = self;
        self.collectionView.dataSource = self;
        [self.view addSubview:self.collectionView];
    
        UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doGesture)];
        tapGesture.delegate = self;
        [self.view addGestureRecognizer:tapGesture];
    }
    
    - (void)doGesture
    {
        NSLog(@"%@",@"doGesture");
    }
    
    - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
    {
        return 100; …
    Run Code Online (Sandbox Code Playgroud)

objective-c ios uitapgesturerecognizer uicollectionview

1
推荐指数
1
解决办法
1262
查看次数