iOS 事件穿透
- (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 事件穿透的更多相关文章
- iOS之事件穿透
前言 小伙伴们在开发中是否遇到过这样的需求呢,一个控件的某个部分被另外一个控件遮挡住,当点击这个重叠部分时,需要响应被遮盖控件的点击事件,就如下图所示 当我们点击区域3时,响应蓝色按钮的点击事件, ...
- 弹层蒙版(mask),ios滚动穿透,我们项目的解决方案
问题描述 项目开发遇到一个ios独有的问题,在wkwebview中稳定复现 问题: 弹出一个蒙版,当在蒙版上面滑动的时候蒙版后面的内容滚动了 这当然是ios的bug,但是经过我们测试iphone7也会 ...
- 深入浅出iOS事件机制
原文地址: http://zhoon.github.io/ios/2015/04/12/ios-event.html 本文章将讲解有关iOS事件的传递机制,如有错误或者不同的见解,欢迎留言指出. iO ...
- 支持事件穿透?使用pointer-events样式
使用绝对定位元素,让元素A完全盖住元素B时,如何通过元素A来响应元素B的事件呢? 上图可以用下面的SVG代码来实现: <svg width="200" height=&quo ...
- 手机端 zepto tap事件穿透
什么是事件穿透? 点击上面的一层时会触发下面一层的事件 ”google”说原因是“tap事件实际上是在冒泡到body上时才触发”,也就是Zepto的tap事件是绑定在document上的,所以会导致 ...
- iOS事件:触摸事件.运动事件.远程控制事件
iOS中,提供了事件处理:触摸事件,运动事件,远程控制事件.这很大得方便程序猿的工作. 这里先简单做个介绍: // // ViewController.m // demo // // Created ...
- iOS事件机制(二)
从上一篇的内容我们知道,在iOS中一个事件用一个UIEvent对象表示,UITouch用来表示一次对屏幕的操作动作,由多个UITouch对象构成了一个UIEvent对象.另外,UIResponder是 ...
- iOS事件机制(一)
运用的前提是掌握 掌握的本质是理解 本篇内容将围绕iOS中事件及其传递机制进行学习和分析.在iOS中,事件分为三类: 触控事件(单点.多点触控以及各种手势操作) 传感器事件(重力.加速度传感器等) 远 ...
- 谈一谈iOS事件的产生和传递
谈一谈iOS事件的产生和传递 1.事件的产生 发生触摸事件后,系统会将该事件加入到一个由UIApplication管理的事件队列中. UIApplication会从事件队列中取出最前面的事件,并将事件 ...
随机推荐
- OneDrive无法正常登录
可能是DNS被污染 手动设置DNS 134.170.108.26 onedrive.live.com134.170.108.152 skyapi.onedrive.live.com
- java RMI
import java.rmi.*; public interface Hello extends Remote { public String getGreeting() throws Remote ...
- Java Phaser
//Listing 6-5. Using a Phaser to Control a One-Shot Action Serving a Variable Number //of Parties im ...
- NSURLSession
参考文章1, apple文档 一.NSURLSessionConfiguration 介绍:分别配置每一个 session 对象.(NSURLConnection 很难做到) 分类: 1) defau ...
- js 判断js函数、变量是否存在
//是否存在指定函数 function isExitsFunction(funcName) { try { if (typeof(eval(funcName)) == "function&q ...
- AOP 底层技术比较
表 1. AOP 底层技术比较 AOP 底层技术 功能 性能 面向接口编程 编程难度 直接改写 class 文件 完全控制类 无明显性能代价 不要求 高,要求对 class 文件结构和 Java 字节 ...
- js保留n位小数
1.功能:将浮点数四舍五入,取小数点后2位 function toDecimal(num) { var f = parseFloat(num); if (isNaN(f)) { return; } f ...
- MFC之目录结构及消息流转(一)
跟上时代,用vs2010, 新建一个MFC应用程序Helloworld. 目录结构: 所有文件分为6个部分:解决方案相关文件.工程相关文件.应用程序头文件和源文件.资源文件.预编译头文件和编译链接生成 ...
- 批量处理_cmd_matlab
cd \ cd D:\Projects_Face_Detection\Datasets\afw d: dir /b/s/p/w *jpg > Path_Images.txt 1.ground_t ...
- sqlserver中表变量和变量表之间区别
sqlserver中表变量和变量表之间区别