UIView-4-EventForViews(在view上加入button时候的事件处理)
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
//创建view对象
UIView *myview = [[UIView alloc]init];
myview.frame = CGRectMake(50, 100, 150, 100);
[self.view addSubview:myview];
//设置背景颜色
myview.backgroundColor = [UIColor greenColor];
//设置是否能接受事件,默认是YES
myview.userInteractionEnabled = NO;
//创建button
UIButton * btn = [[UIButton alloc]init];
btn.frame = CGRectMake(50, 100, 250, 40);
[myview addSubview:btn];
btn.backgroundColor = [UIColor redColor];
//注册事件
[btn addTarget:self action:@selector(onClick:) forControlEvents:UIControlEventTouchDown];
//1.如果父视图不能接受事件,则子视图也不能接受事件
//2.子视图超出父视图的部分不能接受事件
[btn removeFromSuperview];
[self.view addSubview:btn];
[self.view insertSubview:btn belowSubview:myview];
//3.如果上面视图覆盖下面视图而且能接受事件,则下面视图不会收到事件了
//4.UILabel和UIImageView 默认不能接受事件
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - button处理方法
- (void)onClick:(UIButton *)btn
{
NSLog(@"button press!");
}
@end
UIView-4-EventForViews(在view上加入button时候的事件处理)的更多相关文章
- view上添加点手势 button无法响应点击事件
在view 上添加手势 有的时候 会把Button的 点击事件盖掉,这个 时候 我们用UITapGestureRecognizer的代理方法 //手势的代理方法 - (BOOL)gestureRec ...
- iOS 在tableView上添加button导致按钮没有点击效果和不能滑动的 zhuang
转载请注明出处. 今天在调试代码的时候,在tableviewcell上添加button,发现button快速点击的话,是看不出点击效果的,查找资料发现, ios7上UITableViewCell子层容 ...
- 关于iOS自定义控件:在view上实现事件和代理
自定义控件.h #import <UIKit/UIKit.h> #import "PPViewtouchesBeginDelegate.h" @interface PP ...
- 一个可以将 json 字符串 直接绑定到 view 上的Android库
android-data-binding 这是一个可以将 json 字符串 直接绑定到 view 上的库, 不用先将 json 转换为 model 类. 传送门(https://github.com/ ...
- 给View添加手势,防止点击View上其他视图触发点击效果
在开发过程中,我们可能会遇到这个问题. 当我们给一个view添加了手势,但是我们又不想点击view上面的视图也触发手势.如下图: 我们在红色view上添加了手势,但是又不想点击黄色view也触发.其实 ...
- ios上的 button和input-button为什么不水平居中的
在iphone6plus上的button中文本上不居中,如下图: 造成的原因,是button的padding不为零,造成的,因而设置padding: 0:就可以解决
- iOS constraint被应用于view上的时间
在viewdidload时,constraint是没有被应用的,之后在layoutSubviews时,系统应用了constraint.但是我感觉在viewWillLayoutSubviews函数时就已 ...
- IOS开发中--点击imageView上的Button没有任何反应
点击imageView上的Button没有任何反应: 解决方法:设置图片的userInteractionEnabled为YES,使该imageView可以与用户进行交互
- 遍历父视图上的button
for (UIView * thebtn in [self.view subviews]) { if ([thebtn isKindOfClass:[UIButton class]]) { //*** ...
随机推荐
- Debug with jdb
原文地址: http://www.javaworld.com/article/2077445/testing-debugging/debug-with-jdb.html Q: How do you u ...
- flex 简单跑马灯效果(竖着显示)
<mx:Move id="move_area" target="{VBox_AreaWarning}"/> //move效果,模拟跑马灯 <s ...
- mysql中查询"_"这种特殊字符
http://www.w3school.com.cn/sql/sql_wildcards.asp SQL 通配符 在搜索数据库中的数据时,SQL 通配符可以替代一个或多个字符. SQL 通配符必须与 ...
- Codeforces Round #334 (Div. 2) A. Uncowed Forces 水题
A. Uncowed Forces Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/604/pro ...
- Codeforces Beta Round #85 (Div. 1 Only) A. Petya and Inequiations 贪心
A. Petya and Inequiations Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest ...
- Codeforces gym 100685 A. Ariel 暴力
A. ArielTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100685/problem/A Desc ...
- mmc运输问题
运输问题,有生产和需求平衡,不平衡, 实际模型,没有多大意义,只是变个符号而已. 下面的是平衡的,如果不平衡,约束变一下就可以了.
- 从Wolframserver获取DC comics卡通人物数据
背景知识 DC comics是美国时代华纳旗下DC娱乐下属的一个漫绘图书出版商. 超人.蝙蝠侠之类漫画的始作俑者. 在Wolfram的眼下为止3750个PopularCurves数据中(所有下载数据有 ...
- 【android】在eclipse中查看genymotion模拟器的sd卡文件夹
假设用google自带模拟器或者真机调试时,sd卡文件夹是在/mnt/sdcard.这个相信大家都知道. 但是今天用genymotion调试时.发现根本打不开/mnt/sdcard这个文件夹,当时也没 ...
- POJ 3074 Sudoku (Dancing Links)
传送门:http://poj.org/problem?id=3074 DLX 数独的9*9的模板题. 具体建模详见下面这篇论文.其中9*9的数独怎么转化到精确覆盖问题,以及相关矩阵行列的定义都在下文中 ...