当前位置:网站首页>Transmission and response of events and use cases
Transmission and response of events and use cases
2022-06-12 13:40:00 【Li. CQ】
Where response chains are used in a project
1. stay scrollView Add slider
// - Scheme 1
-(BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event{
if (CGRectContainsPoint(self.subView.frame, point)) {
self.scrollEnabled = NO;
return YES;
}
self.scrollEnabled = YES;
return YES;
}
// - Option two
-(UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event{
if (CGRectContainsPoint(self.subView.frame, point)) {
self.scrollEnabled = NO;
return [super hitTest:point withEvent:event];
}
self.scrollEnabled = YES;
return [super hitTest:point withEvent:event];
}
// - Option three
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
UIView *view = [super hitTest:point withEvent:event];
if([view isKindOfClass:[UISlider class]]) {
self.scrollEnabled = NO;
} else {
self.scrollEnabled = YES;
}
return view;
}
2. Set up scrollview Do the tab view On the first option, you can slide back to the left
// - Set up scrollview Do the tab view On the first option, you can slide back to the left
-(UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event{
if ([[super hitTest:point withEvent:event] isKindOfClass:[UIControl class]]) {
return [super hitTest:point withEvent:event];
}else{
if ((self.contentOffset.x == 0) && (point.x < 30)) {
return nil;
}
return [super hitTest:point withEvent:event];
}
}
3. Let events penetrate view
// - Set events to penetrate view
@implementation DYContainerBgView
/** Through events */
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event{
if ([super hitTest:point withEvent:event] == self) return nil;
return [super hitTest:point withEvent:event];
}
@end
4. Resolution of event transmission
- A term is used to explain
- events : The order from top to bottom (UIApplication–>UIWindow–> Recursively find the most suitable View), That is, the search process from parent control to child control ( The most important thing in event transmission is to find the right View To receive events , Find from parent view to child view , Same parent view , Add to parent view from behind To First add to view The order of traversal );
- Event response : The order from bottom to top ( Realization View Of touchesBegan Method , If it's time to View Unable to handle event , Is passed up to its parent control ), Pass from child control to parent control ( Find the right View This... Will then be called View Of touches Method to handle specific events , If the current view Do not respond to touch Method , Just find the last responder (superviwe, perhaps view The controller ) To respond to events );
// - Sample code :
- (void)viewDidLoad {
[super viewDidLoad];
QGView *v1 = [[QGView alloc]initWithFrame:CGRectMake(90, 90, 200, 200)];
v1.backgroundColor = [UIColor redColor];
v1.testStr = @"v1";
[self.view addSubview:v1];
QGView *v2 = [[QGView alloc]initWithFrame:CGRectMake(90, 90, 180, 180)];
v2.backgroundColor = [UIColor greenColor];
v2.testStr = @"v2";
[self.view addSubview:v2];
QGView *v3 = [[QGView alloc]initWithFrame:CGRectMake(90, 90, 160, 160)];
v3.testStr = @"v3";
v3.backgroundColor = [UIColor redColor];
[self.view addSubview:v3];
QGView *v31 = [[QGView alloc]initWithFrame:CGRectMake(0, 0, 120, 120)];
v31.backgroundColor = [UIColor greenColor];
v31.testStr = @"v31";
[v3 addSubview:v31];
QGView *v32 = [[QGView alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];
v32.testStr = @"v32";
v32.backgroundColor = [UIColor redColor];
[v3 addSubview:v32];
QGView *v33 = [[QGView alloc]initWithFrame:CGRectMake(0, 0, 80, 80)];
v33.backgroundColor = [UIColor greenColor];
v33.testStr = @"v33";
[v3 addSubview:v33];
}

stay self.view.subView Array , Added after view, The more the element next to the array , stay view The higher the level in , The closer to the user
// - test :
1. Click on v3
2020-05-11 11:12:54.027766+0800 Demo_001[2008:56637] pointInside v3, ruturn : 1
2020-05-11 11:12:54.027995+0800 Demo_001[2008:56637] pointInside v33, ruturn : 0
2020-05-11 11:12:54.028168+0800 Demo_001[2008:56637] hitTest v33, ruturn : (null)
2020-05-11 11:12:54.028309+0800 Demo_001[2008:56637] pointInside v32, ruturn : 0
2020-05-11 11:12:54.028438+0800 Demo_001[2008:56637] hitTest v32, ruturn : (null)
2020-05-11 11:12:54.028569+0800 Demo_001[2008:56637] pointInside v31, ruturn : 0
2020-05-11 11:12:54.028674+0800 Demo_001[2008:56637] hitTest v31, ruturn : (null)
2020-05-11 11:12:54.029436+0800 Demo_001[2008:56637] hitTest v3, ruturn : <QGView: 0x7f9bede05ad0; frame = (90 90; 160 160); layer = <CALayer: 0x600003ec0780>>
2. Click on v33
2020-05-11 11:13:54.777979+0800 Demo_001[2008:56637] pointInside v3, ruturn : 1
2020-05-11 11:13:54.778181+0800 Demo_001[2008:56637] pointInside v33, ruturn : 1
2020-05-11 11:13:54.778399+0800 Demo_001[2008:56637] hitTest v33, ruturn : <QGView: 0x7f9bede0ca40; frame = (0 0; 80 80); layer = <CALayer: 0x600003ec0aa0>>
2020-05-11 11:13:54.778587+0800 Demo_001[2008:56637] hitTest v3, ruturn : <QGView: 0x7f9bede0ca40; frame = (0 0; 80 80); layer = <CALayer: 0x600003ec0aa0>>
3. Click on v31
2020-05-11 11:15:13.166848+0800 Demo_001[2008:56637] pointInside v3, ruturn : 1
2020-05-11 11:15:13.167039+0800 Demo_001[2008:56637] pointInside v33, ruturn : 0
2020-05-11 11:15:13.167145+0800 Demo_001[2008:56637] hitTest v33, ruturn : (null)
2020-05-11 11:15:13.167275+0800 Demo_001[2008:56637] pointInside v32, ruturn : 0
2020-05-11 11:15:13.167396+0800 Demo_001[2008:56637] hitTest v32, ruturn : (null)
2020-05-11 11:15:13.167503+0800 Demo_001[2008:56637] pointInside v31, ruturn : 1
2020-05-11 11:15:13.167669+0800 Demo_001[2008:56637] hitTest v31, ruturn : <QGView: 0x7f9bede08420; frame = (0 0; 120 120); layer = <CALayer: 0x600003ec0a40>>
2020-05-11 11:15:13.167813+0800 Demo_001[2008:56637] hitTest v3, ruturn : <QGView: 0x7f9bede08420; frame = (0 0; 120 120); layer = <CALayer: 0x600003ec0a40>>
4. Click on v1
2020-05-11 11:16:01.172527+0800 Demo_001[2008:56637] pointInside v3, ruturn : 0
2020-05-11 11:16:01.172711+0800 Demo_001[2008:56637] hitTest v3, ruturn : (null)
2020-05-11 11:16:01.172835+0800 Demo_001[2008:56637] pointInside v2, ruturn : 0
2020-05-11 11:16:01.172931+0800 Demo_001[2008:56637] hitTest v2, ruturn : (null)
2020-05-11 11:16:01.173068+0800 Demo_001[2008:56637] pointInside v1, ruturn : 1
2020-05-11 11:16:01.173249+0800 Demo_001[2008:56637] hitTest v1, ruturn : <QGView: 0x7f9bede06520; frame = (90 90; 200 200); layer = <CALayer: 0x600003ec01e0>>
Conclusion : Current vc All of the subView, Call from outside to inside ; Find it from view Of subView in , Call from outside to inside
边栏推荐
- Debug code to quickly locate the error location
- Wechat web developer tools tutorial, web development issues
- Codeforces 1638 D. Big Brush —— BFS
- C language structure
- Resume NFT platform trustrecruit joined Octopus network as a candidate application chain
- Multi source BFS problem template (with questions)
- leetcode 47. Permutations II full permutations II (medium)
- 1002: output the second integer
- import torch_ Geometric loads some common datasets
- Actual combat | realizing monocular camera ranging by skillfully using pose solution
猜你喜欢
FFmpeg 学习指南

How to balance multiple losses in deep learning?

go-zero 微服务实战系列(二、服务拆分)

Pytoch official fast r-cnn source code analysis (I) -- feature extraction

Implementing tensorflow deep learning framework similarflow with numpy

import torch_geometric 的Data 查看

Successful job hopping Ali, advanced learning

C#DBHelper_ FactoryDB_ GetConn

torch_geometric mini batch 的那些事

Tensorrt, onnx to tensorrt in mmclas
随机推荐
Actual combat | realizing monocular camera ranging by skillfully using pose solution
1414: [17noip popularization group] score
Qualcomm platform development series (Protocol) QMI brief introduction and usage
Computational hierarchy -- the problem of large numbers multiplying decimals
创新实训(十一)开发过程中的一些bug汇总
618进入后半段,苹果占据高端市场,国产手机终于杀价竞争
Pre research of image scanning tool
Stm32f1 and stm32subeide programming example - device driver -dht11 temperature sensor driver
1001:Hello,World
There was an error installing mysql. Follow the link below to CMD
5V升压到12.6V的锂电池充电IC芯片方案FS4062B
高通平台开发系列讲解(协议篇)QMI简单介绍及使用方法
Successful job hopping Ali, advanced learning
Teach you how to create SSM project structure in idea
Application of short circuit expression (||) in C language
上海解封背后,这群开发者“云聚会”造了个AI抗疫机器人
Informatics Olympiad all in one 1000: introductory test questions
The problem of Joseph in Informatics
Semantic segmentation with pytorch
Does jupyternotebook have a Chinese character database. Can you recognize handwritten Chinese in deep learning