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. Polymer——Web Components的未来

    什么是polymer? polymer由谷歌的Palm webOS团队打造,并在2013 Google I/O大会上推出,旨在实现Web Components,用最少的代码,解除框架间的限制的UI 框 ...

  2. Leetcode Largest Number c++ solution

    Total Accepted: 16020 Total Submissions: 103330     Given a list of non negative integers, arrange t ...

  3. ACM1994

    /* Problem Description 为自行解决学费,chx勤工俭学收入10000元以1年定期存入银行,年利率为3.7% .利率按年计算,表示100元存1年的利息为3.7元.实际上有时提前有时 ...

  4. linux内核书籍

    1, 关于操作系统理论的最初级的知识.不需要通读并理解<操作系统概念><现代操作系统>等巨著,但总要知道分时(time-shared)和实时(real-time)的区别是什么, ...

  5. C++问题-无法打开某个自定义源文件

    问题经过:需要做一个工具,是在某个产品的基础上做的,所以要来了同事的代码.用VS打开后,提示如下问题.1>c1xx : fatal error C1083: 无法打开源文件:“..\..\GUX ...

  6. JavaIO(03)字节流--OutputStream and InputStream

    IO概述:   IO流用来处理设备之间的数据传输 java对数据的操作是通过流的方式 java用于操作流的对象都在IO包中 流按操作数据分为两种:字节流与字符流(编码表) 流按流向分为:输入流,输出流 ...

  7. AfxGetMainWnd()函数用法

    CWnd* AfxGetMainWnd( ); 使用AfxGetMainWnd函数获取MFC程序中的主框架类指针是一个常用作法. 就是获得应用程序主窗口的指针,AfxGetMainWnd()-> ...

  8. android中的Cursor类

    转载: 使用过 SQLite 数据库的童鞋对 Cursor 应该不陌生,如果你是搞.net 开发你大可以把Cursor理解成 Ado.net 中的数据集合相当于dataReader.今天特地将它单独拿 ...

  9. MVC基本学习

    asp.net MVC ViewData详解 http://www.cnblogs.com/gaopin/archive/2012/11/13/2767515.html Asp.net MVC中的Vi ...

  10. sql 调用函数的方法

    USE [ChangHong_612]GO/****** Object: StoredProcedure [dbo].[st_MES_RptInspectWeight] Script Date: 09 ...