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上点击无效果问题的更多相关文章

  1. 尽量避免把弹窗加在window上,可以考虑把弹窗封装到控制器里面

    封装自定义弹窗,一般来说有两种选择: 在[[[UIApplication sharedApplication] delegate] window]上add自定义view: present一个模态Con ...

  2. nodejs 微信中使用file组件上传图片在某些机型上点击无反应

    看下下面的代码: <form action="/" class="file_upload" method="post" enctype ...

  3. win10开始键点击无效果

    1.在键盘上按下win+R键,或在开始菜单图标上点击右键选择运行: 2.输入powershell,按下“确定”运行:3.在窗口里输入或复制粘贴以下命令,注意只有一行: Get-AppxPackage ...

  4. 关于iOS UIWebView 加载网页,点击网页内某些控件导致 Application 'UIKitApplication:xxx.xxx.xxx' was killed by jetsam.

    问题:公司用的腾讯问卷系统,内嵌在我们应用或游戏的自定义UIWebView里面展示,发现在iOS 10 以下系统,点击圆形勾选框 会大概率出现闪退. 通过联调发现:报了这样一个警告Applicatio ...

  5. ios uibutton加数字角标

    http://www.jianshu.com/p/0c7fae1cadac 第一种:https://github.com/mikeMTOL/UIBarButtonItem-Badge第二种:https ...

  6. [转载]使用iscroll.js-tab左右滑动导航--tab点击无效果

     转载自:http://blog.csdn.net/zuoyiran520081/article/details/77369421 最近在页面中用iscroll.js,但是但是有跳转,用a标签的hre ...

  7. IOS UIButton用法详解

    这段代码动态的创建了一个UIButton,并且把相关常用的属性都列举了.希望对大家有用.   //这里创建一个圆角矩形的按钮UIButton *button1 = [UIButton buttonWi ...

  8. ios 按钮点击无反应

    今天项目遇到有个UIButton无法点击,弄了半天,总结出以下几个结论 1.如果一个UIButton的frame超出父视图的frame,UIButton还是可以显现的,但响应不了点击事件了,当开发中, ...

  9. iOS网络加载图片缓存策略之ASIDownloadCache缓存优化

    iOS网络加载图片缓存策略之ASIDownloadCache缓存优化   在我们实际工程中,很多情况需要从网络上加载图片,然后将图片在imageview中显示出来,但每次都要从网络上请求,会严重影响用 ...

随机推荐

  1. 【剑指offer 面试题23】从上往下打印二叉树

    思路: 没啥好说的,BFS. C++: #include <iostream> #include <queue> using namespace std; struct Tre ...

  2. Selenium2Library系列 keywords 之 _SelectElementKeywords 之 list_should_have_no_selections(self, locator)

    def list_should_have_no_selections(self, locator): """Verifies select list identified ...

  3. asp.net中遍历界面上所有控件进行属性设置

    * 使用方法: *  前台页面调用方法,重置:    protected void Reset_Click(object sender, EventArgs e)        {           ...

  4. 【转载】cocos2d-x教程 Mac系统下搭建Lua的编码环境

    原文链接:http://blog.csdn.net/u012945598/article/details/17168831   在使用Lua写脚本的时候大家都会因为没有代码提示导致敲代码的效率有所下降 ...

  5. python学习之subprocess模块

    subprocess.Popen 这个模块主要就提供一个类Popen: class subprocess.Popen( args, bufsize=0, executable=None, stdin= ...

  6. Intellij IDEA,WebStorm-keymap(转)

    1. ctrl + shift + n: 打开工程中的文件2. ctrl + j: 输出模板3. ctrl + b: 跳到变量申明处4. ctrl + alt + T: 围绕包裹代码(包括zencod ...

  7. BootStrap入门教程 (一) :手脚架Scaffolding(全局样式(Global Style),格网系统(Grid System),流式格网(Fluid grid System),自定义(Customing),布局(Layouts))

    2011年,twitter的“一小撮”工程师为了提高他们内部的分析和管理能力,用业余时间为他们的产品构建了一套易用.优雅.灵活.可扩展的前端工具集--BootStrap.Bootstrap由MARK ...

  8. C# 与 VC Dll 传输信息

    考虑: 使用string类型传送: 在VC Dll中解析字符: 使用 string 类型将解析的类型传送到C#程序中: 建立VC解析的函数,提高代码可重用性

  9. SCAU 07校赛 10317 Fans of Footbal Teams

    10317 Fans of Footbal Teams 时间限制:1000MS  内存限制:65535K 题型: 编程题   语言: 无限制 Description Two famous footba ...

  10. 集群——LVS理论(转)

    原文:http://caduke.blog.51cto.com/3365689/1544229 当单个服务器性能 不能满足日益增多访问流量时,服务器的扩展策略: Scale Up :向上扩展,提升单个 ...