UIButton加在window上,点击没有效果,找了很久,原来是没有加上这名:[self.window makeKeyAndVisible];

  1. self.window = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen] bounds]];
  2. ViewController *vc = [[ViewController alloc] init];
  3. self.window.rootViewController = vc;
  4. self.window.backgroundColor = [UIColor whiteColor];
  5. [self.window makeKeyAndVisible];
  6.  
  7. view1 = [[UIView alloc] initWithFrame:CGRectMake(, , , )];
  8. view1.backgroundColor = [UIColor blueColor];
  9. [self.window addSubview:view1];
  10.  
  11. UIView *view2 = [[UIView alloc] initWithFrame:CGRectMake(, , , )];
  12. view2.backgroundColor = [UIColor yellowColor];
  13. [self.window addSubview:view2];
  14.  
  15. UIView *view3 = [[UIView alloc] initWithFrame:CGRectMake(, , , )];
  16. view3.backgroundColor = [UIColor redColor];
  17. [self.window addSubview:view3];
  18.  
  19. UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
  20. button.frame = CGRectMake(, , , );
  21. button.userInteractionEnabled = YES;
  22. button.backgroundColor = [UIColor greenColor];
  23. [button setTitle:@"change" forState:UIControlStateNormal];
  24. [button addTarget:self action:@selector(changeView) forControlEvents:UIControlEventTouchUpInside];
  25. [self.window addSubview:button];
  26. NSLog(@"%@",self.window.subviews);
  1. - (void)changeView
  2. {
  3. [self.window bringSubviewToFront:view1];
  4. NSLog(@"%@",self.window.subviews);
  5. }

不要直接加在window上,加在ViewController view上点击有效果

  1. view1 = [[UIView alloc] initWithFrame:CGRectMake(, , , )];
  2. view1.backgroundColor = [UIColor blueColor];
  3. [self.view addSubview:view1];
  4.  
  5. UIView *view2 = [[UIView alloc] initWithFrame:CGRectMake(, , , )];
  6. view2.backgroundColor = [UIColor yellowColor];
  7. view2.tag = ;
  8. [self.view addSubview:view2];
  9.  
  10. UIView *view3 = [[UIView alloc] initWithFrame:CGRectMake(, , , )];
  11. view3.backgroundColor = [UIColor redColor];
  12. [self.view addSubview:view3];
  13.  
  14. UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
  15. button.frame = CGRectMake(, , , );
  16. button.userInteractionEnabled = YES;
  17. button.backgroundColor = [UIColor greenColor];
  18. [button setTitle:@"change" forState:UIControlStateNormal];
  19. [button addTarget:self action:@selector(changeView) forControlEvents:UIControlEventTouchUpInside];
  20. [self.view addSubview:button];
  21. NSLog(@"%@",self.view.subviews);
  1. - (void)changeView
  2. {
  3. [self.view bringSubviewToFront:view1];
  4. UIView *view = [self.view viewWithTag:];
  5. view.backgroundColor = [UIColor purpleColor];
  6. NSLog(@"%@",self.view.subviews);
  7. }

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. xcode 怎么样在发布release版本的时候 不输出log

    我们平时在开发应用的时候,经常会用到 NSLog 来调试我们的程序,而随着项目越来越大,这些用于调试的日志输出就会变得很难管理. 发布正式版的时候一定要屏蔽掉所有后台输出,因为这些输出还是比较消耗系统 ...

  2. Redrain仿酷狗音乐播放器开发完毕,发布测试程序

    转载请说明原出处,谢谢~~ 从暑假到现在中秋刚过,我用duilib开发仿酷狗播放器大概经历了50天.做仿酷狗的意图只是看原酷狗的界面比较漂亮,想做个完整一些的工程来练习一下duilib.今天把写好的程 ...

  3. Codeforces Round #363

    http://codeforces.com/contest/699 ALaunch of Collider 题意:n个球,每个球向左或右,速度都为1米每秒,问第一次碰撞的时间,否则输出-1 贪心最短时 ...

  4. PHP:PHP5.4连接SQLSERVER

    在PHP5.4的环境下要连接SQLSERVER(2005/2008)数据库,需要以下步骤: 1.下载PHP5.4连接SQLSERVER的驱动(两个动态连接库)http://www.microsoft. ...

  5. Apache Spark MLlib的简介

    MLlib 是构建在 Spark 上的分布式机器学习库,充分利用了 Spark 的内存计算和适合迭代型计算的优势,将性能大幅度提升.同时由于 Spark 算子丰富的表现力, 让大规模机器学习的算法开发 ...

  6. ubuntu 备份安装程序列表

    一般情况下,我们重装ubuntu的系统会做如下几个事情 1)修改默认的程序更新源 2)开始根据需求安装软件. 3)配置文件(如vim/tmux等) 对于步骤,只需要cp /etc//etc/apt/s ...

  7. 【转】关于Xcode的Other Linker Flags

    链接器 首先,要说明一下Other Linker Flags到底是用来干嘛的.说白了,就是ld命令除了默认参数外的其他参数.ld命令实现的是链接器的工作,详细说明可以在终端man ld查看. 如果有人 ...

  8. POJ 1502 MPI Maelstrom(最短路)

    MPI Maelstrom Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 4017   Accepted: 2412 Des ...

  9. C#的dll被其他程序调用时,获取此dll正确的物理路径

    当C# dll被其他程序调用时,用Application.StartupPath获取的dll路径并不一定是此dll的物理路径,有可能是调用程序的路径. 以下方法或者能够获取dll正确的物理路径(未经过 ...

  10. Java封装 properties文件操作

    /** * Prop. Prop can load properties file from CLASSPATH or File object. */ public class Prop { priv ...