On a UILongPressGestureRecognizer how do I detect which object generated the event?

前端 未结 3 723
隐瞒了意图╮
隐瞒了意图╮ 2021-02-14 07:45

I have a view with several UIButtons. I have successfully implemented using UILongPressGestureRecognizer with the following as the selector;

- (void)longPress:(         


        
3条回答
  •  别跟我提以往
    2021-02-14 07:56

    If your view contains multiple subViews (like lots of buttons) you can determine what was tapped:

    // Get the position of the point tapped in the window co-ordinate system
    CGPoint tapPoint = [gesture locationInView:nil];
    
    UIView *viewAtBottomOfHeirachy = [self.window hitTest:tapPoint withEvent:nil];
    
    if ([viewAtBottomOfHeirachy isKindOfClass:[UIButton class]])
    

提交回复
热议问题