怎么处理UITabbar上超出点击范围的UIButton

2019-08-23  本文已影响0人  Somnus_chh

类似于这种的使用系统的UITabbarController处理

tabbar

1、创建一个UITabBar+Category文件

.h文件

@interfaceUITabBar (Category)

@property (nonatomic, weak) UIButton * btn;

@end

.m文件

#import "UITabBar+Category.h"

@implementation UITabBar (Category)

- (void)setBtn:(UIButton*)btn{

    objc_setAssociatedObject(self, @selector(btn), btn, OBJC_ASSOCIATION_RETAIN_NONATOMIC);

}

- (UIButton*)btn{

    return objc_getAssociatedObject(self, _cmd);

}

- (UIView*)hitTest:(CGPoint)point withEvent:(UIEvent*)event{

    CGPointhitPoint = [self convertPoint:point toView:self.btn];

    if([self.btn pointInside:hitPoint withEvent:event]) {

        returnself.btn;

    }else{

        return[super hitTest:point withEvent:event];

    }

}

@end

2、在添加+按钮的位置

设置tabbar的btn

以上就👌了。。。。

上一篇 下一篇

猜你喜欢

热点阅读