UIButton右上方添加一个笑button如:

UIButton *button =[UIButton buttonWithType:UIButtonTypeCustom];
    button.frame= CGRectMake(100, 400, 120, 30);
    [self.view addSubview:button];
    UIButton * btn1 = [[UIButton alloc]initWithFrame:CGRectMake(button.frame.size.width-10, -10, 20, 20)];
    [btn1 setImage:[UIImage imageNamed:@"ic_login_weixin"] forState:UIControlStateNormal];
    [button addSubview:btn1];
    button.layer.borderWidth = 1.f;
    button.layer.borderColor = [UIColor blackColor].CGColor;
    [btn1 addTarget:self action:@selector(touches) forControlEvents:UIControlEventTouchUpInside];虽然右上方的but1可以完全显示出来,但是点击btn1不能进行交互,也就是不能触发touches函数。

同理,在UITextFiled的右上方添加一个button如:

UITextField * filed = [[UITextField alloc]initWithFrame:CGRectMake(100, 200, 120, 30)];
    [self.view addSubview:filed];
    filed.borderStyle = UITextBorderStyleRoundedRect;
    filed.layer.masksToBounds = NO;
    UIButton * btn = [[UIButton alloc]initWithFrame:CGRectMake(filed.frame.size.width-5, -5, 10, 10)];
    [filed addSubview:btn];
    btn.backgroundColor = [UIColor redColor];
    self.view.backgroundColor = [UIColor whiteColor];

[btn addTarget:self action:@selector(touches) forControlEvents:UIControlEventTouchUpInside];

点击右上方的btn同样是不能进行交互的,也就是说该事件被filed给拦截了。

实验,将

filed.userInteractionEnabled = NO;

btn.userInteractionEnabled = YES;

同样也会产生冲突不能进行交互。

但是!!!注意!!!但是!!!

实验UIImageView上面添加btn,然后让imageView可以交互,就能完成右上方的小btn点击时间啦!!!

代码如下:

UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(100, 400, 80, 80)];
    UIButton* delBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    delBtn.tag = 101;
    delBtn.frame = CGRectMake(imageView.frame.size.width-20, -10, 30, 30);
    [delBtn setImage:[UIImage imageNamed:@"ic_login_weixin"] forState:UIControlStateNormal];
    [delBtn addTarget:self action:@selector(delBtntouches) forControlEvents:UIControlEventTouchUpInside];
    [imageView addSubview:delBtn];
    [self.view addSubview:imageView];
    imageView.image = [UIImage imageNamed:@"addimage"];
    imageView.backgroundColor = [UIColor redColor];
    UITapGestureRecognizer * ges = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(imageViewTouched)];
    [imageView addGestureRecognizer:ges];
    imageView.userInteractionEnabled= YES;

而且非常有意思的是,当点击除了delBtn的imageView的其它部分,响应的都是imageViewTouched,而点击了delBtn,则相应的是delBtntouches,但是delBtn超出imageview的部分点击也是没有效的。

由此我们可以推论出:uilabel已定也是可以这样来进行小btn的添加

最后:该理论的实际应用:

我们可以 在原来的图像上自定义来写一些图片增删的功能了。

  

UITextFiled,UIButton,UIImageView交互相互之间的事件拦截的更多相关文章

  1. iOS基础 - UIButton - UIImageView

    封装思想:将相同的重复东西保存到方法里,不同的东西用参数代替.不相同的东西交给方法调用者,相同东西自己搞定. 一.UIButton和UIImageView的区别 1.显示图片 1> UIImag ...

  2. UIButton无法响应点击事件

    一.问题描述 因为项目需要,需要UITableView上添加固定的筛选表头,一直固定,不能随UITableView滚动.所以直接将表头与UITableView分离,将它添加到控制器的UIView上,即 ...

  3. 讲讲Android事件拦截机制

    简介 什么是触摸事件?顾名思义,触摸事件就是捕获触摸屏幕后产生的事件.当点击一个按钮时,通常会产生两个或者三个事件--按钮按下,这是事件一,如果滑动几下,这是事件二,当手抬起,这是事件三.所以在And ...

  4. android事件拦截处理机制详解

    前段时间刚接触过Android手机开发,对它的事件传播机制不是很了解,虽然网上也查了相关的资料,但是总觉得理解模模糊糊,似是而非,于是自己就写个小demo测试了一下.总算搞明白了它的具体机制.写下自己 ...

  5. Android 事件拦截机制一种粗鄙的解释

    对于Android事件拦截机制,相信对于大多数Android初学者是一个抓耳挠腮难于理解的问题.其实理解这个问题并不困难. 首先,你的明白事件拦截机制到底是怎么一回事?这里说的事件拦截机制,指的是对触 ...

  6. Unity3D研究院编辑器之Editor的GUI的事件拦截

    OnGUI是Unity上一个时代的UI系统,而现在运行时的UI系统已经被UGUI取代,但是Editor的UI还是在用老的这一套GUI系统.比如unity编辑器里的所有窗口,布局,按钮,拖动条.滚动等等 ...

  7. Android开发系列之事件拦截机制

    对于Android开发者来说理解事件传递机制的重要性,我想应该是不言而喻的.在一个Activity里面,我们经常会重写onTouchEvent事件,可是重写结束之后,对于是返回true还是返回fals ...

  8. Android事件拦截机制简单分析

    前一阶段,在学习的时候,遇到了我觉得的我接触安卓以来的最多的一次事件拦截出来,那个项目,用到了slidemenu側滑菜单条,然后加上tab标签,还有轮播广告,listview上下滑动.viewpage ...

  9. (网页)HTML5 Canvas ( 事件交互, 点击事件为例 ) isPointInPath(转)

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

随机推荐

  1. UVALive 3415 Guardian of Decency(二分图的最大独立集)

    题意:老师在选择一些学生做活动时,为避免学生发生暧昧关系,就提出了四个要求.在他眼中,只要任意两个人符合这四个要求之一,就不可能发生暧昧.现在给出n个学生关于这四个要求的信息,求老师可以挑选出的最大学 ...

  2. 《深入浅出嵌入式底层软件开发》—1. ARM汇编编程基础

    1.1 ARM CPU寄存器 ARM的汇编编程,本质上就是针对CPU寄存器的编程,所以要搞清楚ARM有哪些寄存器:ARM寄存器分为两类:普通寄存器和状态寄存器:普通寄存器一共有16个,分别为R0——R ...

  3. 优雅地使用CodeIgniter 3之Session类库(1)(转)

    相信无数人在使用CI2的Session类库时,遇到各种的坑,各种抱怨,各种不解.在CI中国论坛能搜到大量关于Session类库的提问,说明要想用 好session类库还是得下一番功夫.本文将先从CI2 ...

  4. 图形编程(数值微分DDA)

    #include <iostream> #include <time.h> #include <stdio.h> #include <stdlib.h> ...

  5. Android下实现win8的按钮点击效果

    原理就是自定义一个imageButton,实现动画效果 demo源码下载地址:  请戳这里----------------> 关于回弹张力的效果扩展,可以参考Facebook的开源动画库rebo ...

  6. Http和Https三次握手那些事

    今天我总结了什么是HTTP三次握手,还有HTTPS握手的过程以及为什么HTTPS是安全的. 一:HTTP与TCP/IP区别? --->TPC/IP协议是传输层协议,主要解决数据如何在网络中传输 ...

  7. MBTiles地图瓦片管理工具

    采用C#+GMap.NET+MBTiles数据库来实现. 具有以下功能: 1)  支持单个文件追加到mbtiles数据库. 2)  支持批量导入Google切片组织的地图瓦片. 3)  支持直接对MB ...

  8. As3 计算两个日期之间的天数差

    /*日期转YYYYMMDD*/ formDate.fullYear+""+(formDate.month<10?("0"+formDate.month): ...

  9. Introduction 引言

    The risk of software failure has never been greater. The estimated annual economic impact ranges fro ...

  10. spring开发相关网址

    jar包下载地址:http://repo.springsource.org/libs-release-local/org/springframework/spring/