当前位置: 移动技术网 > 移动技术>移动开发>IOS > iOS事件传递及处理方法

iOS事件传递及处理方法

2018年04月19日  | 移动技术网移动技术  | 我要评论

iOS事件传递及处理方法。UIView继承与UIResponder,UIResponder提供四个处理方法(PS:不使用父类处理,【super之类的,会拦截事件)。

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
NSLog(@"touchBegan");
[super touchesBegan:touches withEvent:event];
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
NSLog(@"touchMoved");
[super touchesMoved:touches withEvent:event];
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
NSLog(@"touchEnded");
[super touchesEnded:touches withEvent:event];
}

- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event{
NSLog(@"touchCancelled");
[super touchesCancelled:touches withEvent:event];
}

 

UIView进行事件分发处理时,两个主要的方法

//此方法用于确定该事件是不是本View内部,也可以人工篡改不拦截事件。(一个view能处理事件的充分必要条件是以下两个都是yes,而且view.userInterfaceEnable = YES 才可以)

- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event{
return YES;
}

//此方法用来确定本View的各个子View中,哪个处理event合适,如果没有合适的子view,就会返回本类

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event{
NSArray * views = self.subviews;
for (UIView * view in views) {
if ([view isKindOfClass:[ButtonC class]]) {
return view;
}
}
return nil;
}

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网