解决UITabbar按钮超出tabbar区域无法点击的问题

#import <UIKit/UIKit.h>

NS_ASSUME_NONNULL_BEGIN

@interface UITabBar (Category)

@property (nonatomic, weak) UIButton * btn;


@end

NS_ASSUME_NONNULL_END
#import "UITabBar+Category.h"

@implementation UITabBar (Category)

//修复超出tabbar无法点击的问题

- (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{
    CGPoint hitPoint = [self convertPoint:point toView:self.btn];
    if ([self.btn pointInside:hitPoint withEvent:event]) {
        return self.btn;
    } else {
        return [super hitTest:point withEvent:event];
    }
}


@end

在UITabbarController中

- (void)expandCameraButtonArea {
    self.tabBar.btn = self.cameraButton;
}

猜你喜欢

转载自www.cnblogs.com/siasyl/p/12765358.html