本打算实现一个点击按钮 弹出 一个landKindView 然后点击屏幕其他部分时移除这个VIew,没想到的是,出了诸多不可思议的问题。
在给这个控制器的View添加手势时,然后居然拦截不到,touchesbegin方法,然后又试了下添加tapGesture,依旧是没有反应 。
然后我试着 在touchesBegin方法中 实现 [super touchesBegins....];依旧是没有任何反应。无奈,又尝试着在View视图上添加一个landBGView,来承载我想要显示的landKindView。
设置 landBGView 为控制器的View的尺寸,然会添加,到控制器的VIew上。然后在landBGView上添加手势,但是仍旧是没有反应,郁闷至极。。。今天再次尝试了一下,居然就可以了(可能是自己修改了某些东西)。
<span style="font-family: Arial, Helvetica, sans-serif;">可能的原因:</span>
1. View的userEnable 的属性查看是否开启 (尤其是父控件)
2. View的叠放顺序 查看是否被其他的控件挡住
<img src="https://img-blog.csdn.net/20160115104129525?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" width="200" height="40" alt="" /><img src="https://img-blog.csdn.net/20160115104156814?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" width="200" height="150" alt="" />
3.查看是否添加事件监听
4.查看是否被添加的手势监听拦截
5.对父控件进行上述可能存在的问题检查
(暂时想到这么多)
<span style="white-space:pre">  </span>但是也在尝试做一些其他的东西。重写set方法来实现某些代码的简化,
主要是操作View的显示与隐藏(或者是刷新操作,网络请求之类的均可),主要是为了操作方便,集中处理细节问题
具体如下:
//某按钮的 控制显示子View
- (void)categoryBtnClick
{self.categoryIsShowing = !self.categoryIsShowing ;
}// 重写set方法
- (void)setCategoryIsShowing:(BOOL)categoryIsShowing
{if (categoryIsShowing == YES) {_categoryIsShowing =YES;[self.view addSubview: self.landBGView];} else {_categoryIsShowing =NO;[self.landBGView removeFromSuperview];}
}
//这是背景view
- (UIView *)landBGView
{if (!_landBGView) {self.landBGView = [[UIViewalloc] initWithFrame:self.view.bounds];
//        self.landBGView.backgroundColor = [UIColor lightGrayColor];[self.landBGViewaddSubview:self.landKindView];UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizeralloc] initWithTarget:selfaction:@selector(toucheslandBGView)];[self.landBGView addGestureRecognizer:tapGesture];}return_landBGView;
}//
- (UIView *)landKindView
{if (!_landKindView) {NSArray *landKinds  = [NSArrayarrayWithObjects:@"AAA",@"BBB",@"CCC",nil];CGFloat detailViewX = [UIScreenmainScreen].bounds.size.width -100;//    CGFloat detailViewX = 200;CGFloat detailViewY = 64;CGFloat detailViewW = 100;CGFloat detailViewH = 44 * 3;UIView  *landKindView = [[UIViewalloc] initWithFrame:CGRectMake(detailViewX, detailViewY, detailViewW, detailViewH) ];landKindView.backgroundColor = [UIColorlightGrayColor];CGFloat btnY = 0;CGFloat btnH = 44;for (int i =0; i < 3; i++) {UIButton *btn =  [[UIButtonalloc] initWithFrame:CGRectMake(0, btnY + i*btnH, detailViewW, btnH)];btn.tag = i;[btn setTitle:landKinds[i]forState:UIControlStateNormal];[btn addTarget:selfaction:@selector(landCategoryBtnClick:)forControlEvents:UIControlEventTouchUpInside];btn.layer.cornerRadius =5;btn.layer.borderWidth =2;btn.layer.borderColor = [UIColorlightGrayColor].CGColor;//[btn setBackgroundColor:[UIColor blueColor]];[landKindView addSubview:btn];UIView *lineView = [[UIViewalloc] initWithFrame:CGRectMake(0 +2, btnY + i*btnH -1, detailViewW - 4, 1)];lineView.backgroundColor = [UIColorgrayColor];[landKindView addSubview:lineView];}landKindView.layer.cornerRadius =5;self.landKindView = landKindView;}return_landKindView;
}// 分类按钮
- (void)landCategoryBtnClick:(UIButton *)btn
{NSInteger index = btn.tag;switch (index) {case 0:{NSString *message = @"AAA";UIAlertView *alert = [[UIAlertViewalloc] initWithTitle:@"提示"message:message delegate:selfcancelButtonTitle:@"确定"otherButtonTitles:nil,nil];[alert show];break;}case 1:case 2:{NSString *message =@"BBB,CCC";UIAlertView *alert = [[UIAlertViewalloc] initWithTitle:@"请稍候"message:message delegate:selfcancelButtonTitle:@"取消"otherButtonTitles:@"确定",nil];[alert show];break;}default:break;}
}#pragma  mark alertView  代理方法
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{[self.landBGViewremoveFromSuperview];self.categoryIsShowing =NO;if (buttonIndex == 0) {return;}else{//意见反馈FeedbackController * feedVC = [[FeedbackControlleralloc]init];[self.navigationControllershowViewController:feedVC sender:nil];}}

奇怪的现象:touchesBegan: 与UITapGestureRecognizer手势没有人响应 以及set方法的妙用相关推荐

  1. 发现一个很奇怪的现象,MyBaits 的 insert方法一直返回-2147482646

    点击关注公众号,Java干货及时送达来源:cnblogs.com/wyq178/p/8652443.html 前几天在做项目demo的时候,发现有一个很奇怪的现象: 就是MyBatis发现更新和插入返 ...

  2. iOS UITapGestureRecognizer手势和UIButton 以及UITabelView点击事件冲突

    一:在同一个view上加载,UITapGestureRecognizer手势,UIButton 行为,UITabelView点击事件冲突: 二:解决方式: 在UITapGesttureRecogniz ...

  3. Git cherry-pick后再merge出现一个“奇怪”的现象

    背景描述:有的时候基于一个master branch拉出一个独立feature分支做开发时,两条分支都在并行开发,如果master分支增加了某些功能,解决了某些关键bug,而独立feature分支不需 ...

  4. get请求400错误 vue_vue用get请求,一个很奇怪的现象

    页面长这样: 打印出来的是选中的id 点击"确定"后,我向后端发送一个get请求 this.$axios.get('/crossSchool',{ params:{ itemUid ...

  5. android 手势事件 重写,Android实现通过手势控制图片大小缩放的方法

    本文实例讲述了Android实现通过手势控制图片大小缩放的方法.分享给大家供大家参考,具体如下: 该程序实现的是通过手势来缩放图片,从左向右挥动图片时图片被放大,从右向左挥动图片时图片被缩小,挥动速度 ...

  6. ROS---进行建图或者move_base路径规划时出现打滑现象(雷达匹配不上地图)的解决方法 附gmapping建图配置参数

    ROS-进行建图或者move_base路径规划时出现打滑现象(雷达匹配不上地图)的解决方法-本人多次实验的出的结论 之前我的车会经常出现打滑现象,图也建不了,就算勉强建好了图,在进行路径规划的时候也是 ...

  7. [Xcode 实际操作]二、视图与手势-(12)UITapGestureRecognizer手势之双击

    目录:[Swift]Xcode实际操作 本文将演示使用视图的双击手势,完成视图的交互功能. 1 import UIKit 2 3 class ViewController: UIViewControl ...

  8. iOS开发 解决UITapGestureRecognizer手势与UITableView的点击事件的冲突

    该篇文章摘自我的新浪博客,原文地址为: http://blog.sina.com.cn/s/blog_dcc636350102wavx.html UITableView 拥有属于自己的点击事件,在将一 ...

  9. Tensorflow_yolov3 Intel Realsense D435奇怪的现象,多摄像头连接时一旦能检测到深度马上就会卡(卡住)

    两个摄像头连接时一旦能检测到深度马上就会卡(小于30公分),,单个摄像头没事,这是使用了多线程传输后的现象,不知咋回事... 后来加了这句验证全局变量是否存在,好像好点了,有待验证 20200401 ...

最新文章

  1. java 的继承_关于java中的继承
  2. 2.创建适合游戏的窗口和消息循环
  3. Equipment upload 不起作用的分析
  4. Python——使用matplotlib绘制柱状图
  5. 【POJ - 2909 】Goldbach's Conjecture (哥德巴赫猜想,数论,知识点结论)
  6. [转载]VirtualBox网络配置详解
  7. 【报告分享】激荡2020--吴晓波疫情特别演讲PPT.pdf(附下载链接)
  8. 如何用Linux搭建家庭云服务,使用ownCloud在Linux安装你的个人云服务 私有云的搭建...
  9. lua代码格式化工具_lua的代码覆盖率工具
  10. macbookpro bootcamp win10 蓝牙鼠标卡顿解决方案
  11. Unicode字符编码分布表――语言文字类
  12. 大数据资料全解析(352个案例+大数据交易白皮书+国内外政策汇篇)
  13. 在日软件工程师的远虑近忧
  14. layui后台首页关闭标签
  15. 切割木板 (贪心)
  16. k8s pod基础概念
  17. 是时候为各式设备适配完善的输入支持了
  18. 计算机导论未来规划,计算机导论论文-论对软件专业的认识和对未来四年的规划...
  19. python实现视频分割
  20. Transformer主干网络——DeiT保姆级解析

热门文章

  1. 用Python分析了某大学2000千条表白墙,甜到发腻,原来脱单的秘密是……
  2. Deepin V20安装
  3. zuul网关找不到服务_Zuul网关服务
  4. Derek Sivers:记日记和专题记录的收获(译)
  5. java怎么屏蔽部分代码快捷键,html屏蔽各种快捷键
  6. Python 子类继承多个父类属性
  7. 底层网络知识详解:从二层到三层-第9讲-路由协议:西出网关无故人,敢问路在何方
  8. selenium+java破解极验滑块验证码
  9. ps画笔圈大小快速调节 增加选区减少选区交叉选区快捷键
  10. 《未来呼啸而来》概览