- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[selftouchPoint:toucheswithEvent:event];
[supertouchesBegan:toucheswithEvent:event];
}
- (void)touchPoint:(NSSet *)touches withEvent:(UIEvent *)event
{
//Get the point user touched
UITouch *touch = [touchesanyObject];
// 关键代码
CGPoint touchPoint = [touchlocationInView:self];
UIView *subview = [selfhitTest:touchPointwithEvent:nil];
if ([subviewisKindOfClass:[PNBarclass]] && [self.delegaterespondsToSelector:@selector(userClickedOnBarAtIndex:)]) {
[self.delegateuserClickedOnBarAtIndex:subview.tag];
}
}
本文介绍了一个iOS应用中处理触控事件的方法。通过覆写UIView的touchesBegan方法,并定义了一个touchPoint方法来获取用户触摸的位置。当用户触摸屏幕时,会获取到触摸点的位置,并通过hitTest方法找到被触摸视图。如果被触摸的是PNBar类的子视图且委托对象响应userClickedOnBarAtIndex选择器,则调用委托方法。

9万+

被折叠的 条评论
为什么被折叠?



