Passing through touches to UIViews underneath

前端 未结 5 1378
庸人自扰
庸人自扰 2020-12-01 03:17

I have a UIView with 4 buttons on it and another UIView on top of the buttons view. The top most view contains a UIImageView with a <

5条回答
  •  难免孤独
    2020-12-01 04:09

    Look into the UIGestureRecognizerDelegate Protocol. Specifically, gestureRecognizer:shouldReceiveTouch:

    You'll want to make each UIGestureRecognizer a property of your UIViewController,

    // .h
    @property (nonatomic, strong) UITapGestureRecognizer *lowerTap;
    
    // .m
    @synthesize lowerTap;
    
    // When you are adding the gesture recognizer to the image view
    self.lowerTap = tapGestureRecognizer
    

    Make sure you make your UIViewController a delegate,

    [self.lowerTap setDelegate: self];
    

    Then, you'd have something like this,

    - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
        if (expanded && gestureRecognizer == self.lowerTap) {    
            return NO;
        }
        else {
            return YES;
        }
    }
    

    Of course, this isn't exact code. But this is the general pattern you'd want to follow.

提交回复
热议问题