控制局部对触摸的响应与否

Posted liuyongfa

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了控制局部对触摸的响应与否相关的知识,希望对你有一定的参考价值。

BView遮挡AView,BView有子viewB1,AView有手势。希望点击在B1中的时候,AView可以响应手势。

若果让BView整个userInteractionEnabled = NO,那么点击在BView的任何地方,AView的手势都会响应,不符合要求。

可以用一下函数实现

- (BOOL)pointInside:(CGPoint)point withEvent:(nullable UIEvent *)event;   // default returns YES if point is in bounds

@interface BView ()
@property (strong, nonatomic) UIView *B1;

@end

@implementation LYFControlsView

...

- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event 
    if ([self.B1 pointInside:[self convertPoint:point toView:self.B1] withEvent:event]) 
        //如果点击在B1内,就不再传递,让出响应
        return NO;
    
    return YES;

@end

 

以上是关于控制局部对触摸的响应与否的主要内容,如果未能解决你的问题,请参考以下文章