变更记录
序号 | 录入时间 | 录入人 | 备注 |
---|---|---|---|
1 | 2016-04-06 | Alfred Jiang | - |
方案名称
UIScrollView - UIScrollView 添加 UIButton 时不响应滑动操作
关键字
手势 \ UILabel \ UIView \ 单击手势 \ UIScrollView \ UITableViewCell \ UIButton \ 滑动
需求场景
- 解决 UIScrollView \ UITableViewCell 添加 UIButton 时不响应滑动操作问题
- 解决 UIScrollView 中添加 UITapGestureRecognizer 跟 UIButton 点击事件冲突
参考链接
详细内容
UIScrollView \ UITableViewCell 添加 UIButton 时不响应滑动操作问题
//1.添加单击事件
...
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(60, 0, listV.frame.size.width - 60, listV.frame.size.height)];
label.userInteractionEnabled=YES;
label.tag = 100;
UITapGestureRecognizer *labelTapGestureRecognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(labelTouchUpInside:)];
[label addGestureRecognizer:labelTapGestureRecognizer];
...
//2.获取单击事件
-(void) labelTouchUpInside:(UITapGestureRecognizer *)recognizer
{
UILabel *label=(UILabel*)recognizer.view;
NSLog(@"%@ -- Tag : %ld",label.text,label.tag);
}
UIScrollView 中添加 UITapGestureRecognizer 跟 UIButton 点击事件冲突
//1.添加单击事件
...
UITapGestureRecognizer *gensture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(scrollViewTapAction)];
gensture.delegate = self;
[scrollView addGestureRecognizer:gensture];
...
//2.实现 UIGestureRecognizerDelegate 中的代理方法
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
UIView *view = [touch view];
if ([view isKindOfClass:[UIButton class]])
{
return NO;
}
return YES;
}
效果图
(无)
备注
(无)