iOS UIButton加在window上点击无效果问题
UIButton加在window上,点击没有效果,找了很久,原来是没有加上这名:[self.window makeKeyAndVisible];
self.window = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen] bounds]];
ViewController *vc = [[ViewController alloc] init];
self.window.rootViewController = vc;
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible]; view1 = [[UIView alloc] initWithFrame:CGRectMake(, , , )];
view1.backgroundColor = [UIColor blueColor];
[self.window addSubview:view1]; UIView *view2 = [[UIView alloc] initWithFrame:CGRectMake(, , , )];
view2.backgroundColor = [UIColor yellowColor];
[self.window addSubview:view2]; UIView *view3 = [[UIView alloc] initWithFrame:CGRectMake(, , , )];
view3.backgroundColor = [UIColor redColor];
[self.window addSubview:view3]; UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame = CGRectMake(, , , );
button.userInteractionEnabled = YES;
button.backgroundColor = [UIColor greenColor];
[button setTitle:@"change" forState:UIControlStateNormal];
[button addTarget:self action:@selector(changeView) forControlEvents:UIControlEventTouchUpInside];
[self.window addSubview:button];
NSLog(@"%@",self.window.subviews);
- (void)changeView
{
[self.window bringSubviewToFront:view1];
NSLog(@"%@",self.window.subviews);
}
不要直接加在window上,加在ViewController view上点击有效果
view1 = [[UIView alloc] initWithFrame:CGRectMake(, , , )];
view1.backgroundColor = [UIColor blueColor];
[self.view addSubview:view1]; UIView *view2 = [[UIView alloc] initWithFrame:CGRectMake(, , , )];
view2.backgroundColor = [UIColor yellowColor];
view2.tag = ;
[self.view addSubview:view2]; UIView *view3 = [[UIView alloc] initWithFrame:CGRectMake(, , , )];
view3.backgroundColor = [UIColor redColor];
[self.view addSubview:view3]; UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame = CGRectMake(, , , );
button.userInteractionEnabled = YES;
button.backgroundColor = [UIColor greenColor];
[button setTitle:@"change" forState:UIControlStateNormal];
[button addTarget:self action:@selector(changeView) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
NSLog(@"%@",self.view.subviews);
- (void)changeView
{
[self.view bringSubviewToFront:view1];
UIView *view = [self.view viewWithTag:];
view.backgroundColor = [UIColor purpleColor];
NSLog(@"%@",self.view.subviews);
}


iOS UIButton加在window上点击无效果问题的更多相关文章
- 尽量避免把弹窗加在window上,可以考虑把弹窗封装到控制器里面
封装自定义弹窗,一般来说有两种选择: 在[[[UIApplication sharedApplication] delegate] window]上add自定义view: present一个模态Con ...
- nodejs 微信中使用file组件上传图片在某些机型上点击无反应
看下下面的代码: <form action="/" class="file_upload" method="post" enctype ...
- win10开始键点击无效果
1.在键盘上按下win+R键,或在开始菜单图标上点击右键选择运行: 2.输入powershell,按下“确定”运行:3.在窗口里输入或复制粘贴以下命令,注意只有一行: Get-AppxPackage ...
- 关于iOS UIWebView 加载网页,点击网页内某些控件导致 Application 'UIKitApplication:xxx.xxx.xxx' was killed by jetsam.
问题:公司用的腾讯问卷系统,内嵌在我们应用或游戏的自定义UIWebView里面展示,发现在iOS 10 以下系统,点击圆形勾选框 会大概率出现闪退. 通过联调发现:报了这样一个警告Applicatio ...
- ios uibutton加数字角标
http://www.jianshu.com/p/0c7fae1cadac 第一种:https://github.com/mikeMTOL/UIBarButtonItem-Badge第二种:https ...
- [转载]使用iscroll.js-tab左右滑动导航--tab点击无效果
转载自:http://blog.csdn.net/zuoyiran520081/article/details/77369421 最近在页面中用iscroll.js,但是但是有跳转,用a标签的hre ...
- IOS UIButton用法详解
这段代码动态的创建了一个UIButton,并且把相关常用的属性都列举了.希望对大家有用. //这里创建一个圆角矩形的按钮UIButton *button1 = [UIButton buttonWi ...
- ios 按钮点击无反应
今天项目遇到有个UIButton无法点击,弄了半天,总结出以下几个结论 1.如果一个UIButton的frame超出父视图的frame,UIButton还是可以显现的,但响应不了点击事件了,当开发中, ...
- iOS网络加载图片缓存策略之ASIDownloadCache缓存优化
iOS网络加载图片缓存策略之ASIDownloadCache缓存优化 在我们实际工程中,很多情况需要从网络上加载图片,然后将图片在imageview中显示出来,但每次都要从网络上请求,会严重影响用 ...
随机推荐
- 【LeetCode 173】Binary Search Tree Iterator
Implement an iterator over a binary search tree (BST). Your iterator will be initialized with the ro ...
- 《Python CookBook2》 第一章 文本 - 控制大小写 && 访问子字符串
控制大小写 任务: 将一个字符串由大写转成小写,或者泛起到而行之. 解决方案: >>> a = 'a'.upper() >>> a 'A' >>> ...
- 微信多媒体上传图片,创建卡券上传 LOGO
//*****************************************多媒体上传图片 begin******************************************** ...
- SVM:从理论到OpenCV实践
(转载请注明出处:http://blog.csdn.net/zhazhiqiang/ 未经允许请勿用于商业用途) 一.理论 参考网友的博客: (1)[理论]支持向量机1: Maximum Marg ...
- 使用rpmbuild来创建自己的RPM
1. 进行创建必须的目录 在6.2的版本中,路径发生了变化,必须在此路径中,否则必须要修改配置文件. 2. 创建脚本文件 编写一个简单的脚本,然后将脚本进行打包为tar.gz格式的压缩文件,并且将其放 ...
- bzoj 2049 [Sdoi2008]Cave 洞穴勘测(LCT)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=2049 [题意] 给定森林,可能有连边或断边的操作,回答若干个连通性的询问. [思路] ...
- HDU5780 gcd 欧拉函数
http://acm.hdu.edu.cn/showproblem.php?pid=5780 BC #85 1005 思路: 首先原式化简:x^gcd(a,b)−1 也就是求n内,(公约数是i的 ...
- 关于登录的会话控制, 终极解决方案 - chunyu
登录是用cookie还是session实现,一直有争议,普遍认为session更安全,可是有些功能,用cookie最方便也最高效,比如“记住我一周”. cookie还是session,我的答案是两 ...
- Native libraries .so.XY failing to link at runtime
What you need to do is edit the configure file. And find out this: SLIBNAME='$(SLIBPREF)$(FULLNAME)$ ...
- homework-10
不多不说这是一次神奇的作业,作业一拖再拖,到最后发现.... 首先,在一开始的最大字数和问题实现图形界面主要是由我的小伙伴邹同学完成的,所以当我第一次看到说要显示详细运行过程的时候感到很迷茫. 第一感 ...