iOS 修改UIButton的点击范围

来源:互联网 发布:php mysql 事务处理 编辑:程序博客网 时间:2024/06/06 00:07
/** * 按钮点击范围的方法 */- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event {        //首先调用父类的方法确定点击的区域确实在按钮的区域中    BOOL res = [super pointInside:point withEvent:event];    if (res) {        //绘制一个圆形path        UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:self.centerButton.frame];        if ([path containsPoint:point]) {            //如果在path区域内,可以接收交互事件,从而截获父视图的点击事件            self.centerButton.userInteractionEnabled = YES;            return YES;                    } else {                        //如果不在path区域内,不可以接收交互事件,从而将事件传给父视图接收            self.centerButton.userInteractionEnabled = NO;            return YES;        }            }    return NO;}

0 0
原创粉丝点击