检测何时点击视图

时间:2014-06-24 08:56:37

标签: ios objective-c ios6

我在ViewController中有多个视图,我想知道何时点击视图,我不知道如何去做它

1 个答案:

答案 0 :(得分:0)

为了检查是否触摸了另一个视图中的某个视图,您可以使用hitTest。

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

在touchesBegan的自定义实现中,检查触摸设置中的每个触摸。 hitTest方法的点可以使用

获得
- (CGPoint)locationInView:(UIView *)view;
method, where the view is your superView (the one that contains other views).

编辑:这是一个快速的自定义实现:

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { 
    CGPoint locationPoint = [[touches anyObject] locationInView:self];
    UIView* viewYouWishToObtain = [self hitTest:locationPoint withEvent:event];
}

我希望这很有帮助,保罗

资料来源:Detect if certain UIView was touched amongst other UIViews

相关问题