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中显示出来,但每次都要从网络上请求,会严重影响用 ...
随机推荐
- 【LR】版本问题
前台信息工作笔记本系统是: widows7 64位操作系统 (1)loadrunner11 软件 --兼容性问题的解决与环境配置要求 地址:http://bgwan.blog.163.com/blog ...
- sql语句中获取datetime任何部分
sql语句中获取datetime的日期部分 sql语句中 经常操作操作datetime类型数据.今天在写一个存储过程的时候需要将 一个datetime的值的 日期部分提取出来.网上有许多这方面的介绍. ...
- 2015NOIP简单说说
在机房度过最后两节课然后滚回去赶文化课,准备期中考试,高考.AFO的称号毫无悬念的归来了.DAY1T2的失误不能拿下230,只能190滚粗,DAY2一上午都在混沌.旁边的哥们求我给看第一题,于是他就对 ...
- [LeetCode] Single Number III ( a New Questions Added today)
Given an array of numbers nums, in which exactly two elements appear only once and all the other ele ...
- trie树 Codeforces Round #367 D Vasiliy's Multiset
// trie树 Codeforces Round #367 D Vasiliy's Multiset // 题意:给一个集合,初始有0,+表示添加元素,-去除元素,?询问集合里面与x异或最大的值 / ...
- 基础排序算法,java实现(快速,冒泡,选择,堆排序,插入)
1.冒泡排序: (1)比较相邻的元素.如果第一个比第二个大,就交换他们两个. (2)外面再套个循环就行. 算法复杂度:O(N2) 不罗嗦,上代码: //冒泡排序(两两交换,外加一个外循环) pub ...
- NSLog说明
%@ 对象 %d,%i 整型 (%i的老写法) %hd 短整型 %ld , %lld 长整型 %u 无符整型 %f 浮点型和double型 %0.2f 精度浮点数,只保留两位小数 %x,%X 二进制整 ...
- linux下安装apache详解
下载httpd-2.2.6.tar.bz2 把httpd-2.2.6.tar.bz2放到/soft 下[root@localhost ~]#cd /soft[root@localhost soft] ...
- Javascript/Jquery——简单定时器的多种实现方法
第一种方法: <script language="javascript"> //使用setInterval间歇调用 (不建议使用该方法) $(function(){ s ...
- Android应用开发学习之相对布局
作者:刘昊昱 博客:http://blog.csdn.net/liuhaoyutz 相对布局RelativeLayout是指按照组件之间的相对位置进行布局,如一个组件在另一个组件的左边.右边.上边或下 ...