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]]) { //*** ...
随机推荐
- usr/bin/ld: cannot find 错误解决方法
参考:http://blog.siyebocai.cn/20100324_5p424qs7.html 通常在软件编译时出现的usr/bin/ld: cannot find -lxxx的错误,主要的原因 ...
- UOJ #142. 【UER #5】万圣节的南瓜灯 并查集
#142. [UER #5]万圣节的南瓜灯 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://uoj.ac/problem/142 Descrip ...
- HDU 4813 Hard Code 水题
Hard Code Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.act ...
- STL 案例分析
#include <iostream> using namespace std; #include "string" #include <vector> # ...
- JavaScript 中 typeof 知多少?
typeof运算符介绍:typeof 是一个一元运算,放在一个运算数之前,运算数可以是任意类型.它返回值是一个字符串,该字符串说明运算数的类型. 你知道下面typeof运算的结果吗? typeof(1 ...
- Shell脚本调试工具set
可以使用set命令的x选项,显示所有命令执行及变量值的变化过程等. 具体使用方法:首先使用set -x开启调试模式,最后使用命令set +x关闭调试模式. 一个简单示例演示如何使用set命令进行脚本调 ...
- oracle 基本操作
1. 开启oralce和监听#su - oracle$sqlplus / as sysdba>startup>exit$lsnrctl start$ps -ef|grep oracle 一 ...
- 实例源码--Android理财工具源码
下载源码 技术要点: 1.Sqlite数据库的综合使用 2.控件的综合使用 3. 源码带详细的中文注释 ...... 详细介绍: 1. Sqlite数据库的综合使用 本套源码采用了Sqlite ...
- Implementing the skip list data structure in java --reference
reference:http://www.mathcs.emory.edu/~cheung/Courses/323/Syllabus/Map/skip-list-impl.html The link ...
- BootStrap2学习日记8---表单
<form> <label for="username">用户名</label> <input id="username&quo ...