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

前端 未结 3 1947
醉梦人生
醉梦人生 2021-02-14 07:20

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 08:04

    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]])
    

提交回复
热议问题