该问题浪费了3个小时的时间
一 问题描述
自定义UITableViewCell,Cell 中有两个UIImageView 子控件,自控都需要实现双击,让图片全局展示。
二 错误代码
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { BZEffectImgViewCell *cell = [BZEffectImgViewCell cellWithTableView:tableView]; UITapGestureRecognizer *doubleRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handlePinchGestureFrom:) ]; doubleRecognizer.numberOfTapsRequired = 2; /* *为 BZEffectImgViewCell 子空间 beforeImageView,但是事件监听不成功 */ [cell.beforeImageView addGestureRecognizer:doubleRecognizer]; return cell; }
三 正确代码
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { BZEffectImgViewCell *cell = [BZEffectImgViewCell cellWithTableView:tableView]; UITapGestureRecognizer *doubleRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handlePinchGestureFrom:) ]; doubleRecognizer.numberOfTapsRequired = 2; //设置 cell.afterImageView.userInteractionEnabled = YES; 即可 cell.afterImageView.userInteractionEnabled = YES; [cell.beforeImageView addGestureRecognizer:doubleRecognizer]; return cell; }
时间: 2024-12-22 08:05:47