本文介绍: 如图所示,当两个按钮leftButtonrightButton)有一部分区域重合在一起时,而rightButton又是后添加的无法改变层级,此时如果想点击重合的区域触发leftButton的方法,而非rightButton的方法可以rightButton继承一个自定义button类,并在button类.m重写– (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event具体代码如下:- (BOOL)pointInside

如图所示,当两个按钮leftButton、rightButton)有一部分区域重合在一起时,而rightButton又是后添加的无法改变层级,此时如果想点击重合的区域是触发leftButton的方法,而非rightButton的方法,可以rightButton继承一个自定义button类,并在button类.m重写– (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event

具体代码如下
 

– (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event {

    

    /** 重合区域 */

    CGRect overlapRect = CGRectMake(0, 0, 100, 80);

    /** 如果当前点击的区域在重合区域内,响应其他view事件,即return NO */

    if (CGRectContainsPoint(overlapRect, point)){

        return NO;

    }

    return [super pointInside:point withEvent:event];

}

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注