- (void)viewDidLoad {

[super viewDidLoad];

// Do any additional setup after loading the view, typically from a nib.

UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];

btn.frame = CGRectMake(80, 100, 100, 50);

btn.backgroundColor = [UIColor redColor];

[btn setTitle:@"click me" forState:UIControlStateNormal];

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

[self.view addSubview:btn];

MyView1 *view = [[MyView1 alloc] initWithTestFrame:CGRectMake(100, 100, 200, 200)];

[self.view addSubview:view];

}

// ---------------------------------------------自定义VIEW

#import "MyView1.h"

@implementation MyView1

/*

// Only override drawRect: if you perform custom drawing.

// An empty implementation adversely affects performance during animation.

- (void)drawRect:(CGRect)rect {

// Drawing code

}

*/

UIButton *btn;

-(id)initWithTestFrame:(CGRect) frame

{

self = [super initWithFrame:frame];

if(self)

{

self.backgroundColor = [UIColor blueColor];

[self drawView];

//        self.userInteractionEnabled = NO;

}

return self;

}

-(void) drawView

{

btn = [UIButton buttonWithType:UIButtonTypeCustom];

btn.frame = CGRectMake(0, 0, 50, 30);

btn.backgroundColor = [UIColor blackColor];

[btn setTitle:@"btn" forState:UIControlStateNormal];

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

[self addSubview:btn];

}

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event

{

CGRect rect = btn.frame;

BOOL containsPoint = CGRectContainsPoint(rect, point);

if(containsPoint)

{

self.userInteractionEnabled = YES;

}

else

{

self.userInteractionEnabled = NO;

}

UIView *touchedView = [super hitTest:point withEvent:event];

return touchedView;

}

-(void)click

{

NSLog(@"black...");

}

@end

iOS 事件穿透的更多相关文章

  1. iOS之事件穿透

    前言 小伙伴们在开发中是否遇到过这样的需求呢,一个控件的某个部分被另外一个控件遮挡住,当点击这个重叠部分时,需要响应被遮盖控件的点击事件,就如下图所示   当我们点击区域3时,响应蓝色按钮的点击事件, ...

  2. 弹层蒙版(mask),ios滚动穿透,我们项目的解决方案

    问题描述 项目开发遇到一个ios独有的问题,在wkwebview中稳定复现 问题: 弹出一个蒙版,当在蒙版上面滑动的时候蒙版后面的内容滚动了 这当然是ios的bug,但是经过我们测试iphone7也会 ...

  3. 深入浅出iOS事件机制

    原文地址: http://zhoon.github.io/ios/2015/04/12/ios-event.html 本文章将讲解有关iOS事件的传递机制,如有错误或者不同的见解,欢迎留言指出. iO ...

  4. 支持事件穿透?使用pointer-events样式

    使用绝对定位元素,让元素A完全盖住元素B时,如何通过元素A来响应元素B的事件呢? 上图可以用下面的SVG代码来实现: <svg width="200" height=&quo ...

  5. 手机端 zepto tap事件穿透

    什么是事件穿透? 点击上面的一层时会触发下面一层的事件 ”google”说原因是“tap事件实际上是在冒泡到body上时才触发”,也就是Zepto的tap事件是绑定在document上的,所以会导致 ...

  6. iOS事件:触摸事件.运动事件.远程控制事件

    iOS中,提供了事件处理:触摸事件,运动事件,远程控制事件.这很大得方便程序猿的工作. 这里先简单做个介绍: // // ViewController.m // demo // // Created ...

  7. iOS事件机制(二)

    从上一篇的内容我们知道,在iOS中一个事件用一个UIEvent对象表示,UITouch用来表示一次对屏幕的操作动作,由多个UITouch对象构成了一个UIEvent对象.另外,UIResponder是 ...

  8. iOS事件机制(一)

    运用的前提是掌握 掌握的本质是理解 本篇内容将围绕iOS中事件及其传递机制进行学习和分析.在iOS中,事件分为三类: 触控事件(单点.多点触控以及各种手势操作) 传感器事件(重力.加速度传感器等) 远 ...

  9. 谈一谈iOS事件的产生和传递

    谈一谈iOS事件的产生和传递 1.事件的产生 发生触摸事件后,系统会将该事件加入到一个由UIApplication管理的事件队列中. UIApplication会从事件队列中取出最前面的事件,并将事件 ...

随机推荐

  1. redis 应用场景

    1.string类型 : 图片和视频文件,静态文件 2.list 双向链表:回帖ID,我的关注列表,消息队列 length = redis.lpush('users:newest', 'user:go ...

  2. P1003 铺地毯

    水题 #include <bits/stdc++.h> using namespace std; const int maxn = 10005; int n; int x, y, i; s ...

  3. Open Sourcing Kafka Monitor

    https://engineering.linkedin.com/blog/2016/05/open-sourcing-kafka-monitor     https://github.com/lin ...

  4. Machine Learning in Action -- 树回归

    前面介绍线性回归,但实际中,用线性回归去拟合整个数据集是不太现实的,现实中的数据往往不是全局线性的 当然前面也介绍了局部加权线性回归,这种方法有些局限 这里介绍另外一种思路,树回归 基本思路,用决策树 ...

  5. 七 mybatis的延迟加载

    1       延迟加载 1.1     什么是延迟加载 resultMap可以实现高级映射(使用association.collection实现一对一及一对多映射),association.coll ...

  6. vm设置静态ip

    1. 进入虚拟linux系统中,vim /etc/sysconfig/network-scripts/ifcfg-eth0,里面保留以下内容即可: DEVICE=eth0 //使用的网卡标识 BOOT ...

  7. 低功耗蓝牙4.0BLE编程-nrf51822开发(10)-描述符

    特性中的属性有两种:属性值或描述符. 支持通知或指示的特性中默认有一个描述符:客户端特性配置描述符(Client Characteristic Configuration Descriptor,CCC ...

  8. Error Domain=com.alamofire.error.serialization.response Code=-1016 "Request failed: unacceptable con

    AFHTTPSessionManager * manager = [AFHTTPSessionManager manager]; manager.responseSerializer.acceptab ...

  9. python join split

    本文记录python,join和split函数的用法. 参考 http://blog.csdn.net/doiido/article/details/43538833 http://blog.csdn ...

  10. 用JQuery给图片添加鼠标移入移出事件

    $("#addLineImg").mouseover( function(){ $("#addLineImg").attr("src",&q ...