Files
yuyin_ios/SweetParty/主类/Others/TabBar/SPCustomTabBar.m
2025-08-08 11:05:33 +08:00

65 lines
2.1 KiB
Objective-C
Executable File

//
// SPCustomTabBar.m
// SweetParty
//
// Created by bj_szd on 2022/5/31.
//
#import "SPCustomTabBar.h"
@implementation SPCustomTabBar
#pragma mark - init method
- (instancetype)init
{
if (self = [super init]) {
// self.centerBtn = [UIButton buttonWithType:UIButtonTypeCustom];
// UIImage *normalImg = [UIImage imageNamed:@"tab_sweet"];
// [self.centerBtn setImage:normalImg forState:UIControlStateNormal];
// self.centerBtn.frame = CGRectMake((ScreenWidth-50)/2, -10, 50, 50);
// [self addSubview:self.centerBtn];
}
return self;
}
////去掉顶部线
- (void)layoutSubviews
{
[super layoutSubviews];
[self.subviews enumerateObjectsUsingBlock:^(__kindof UIView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
if ([obj isKindOfClass:NSClassFromString(@"_UIBarBackground")]) {
[obj.subviews enumerateObjectsUsingBlock:^(__kindof UIView * _Nonnull obj2, NSUInteger idx, BOOL * _Nonnull stop) {
//[array addObject:obj2];
if ([obj2 isKindOfClass:[UIVisualEffectView class]]) {
[obj2.subviews enumerateObjectsUsingBlock:^(__kindof UIView * _Nonnull obj3, NSUInteger idx, BOOL * _Nonnull stop) {
if ([obj3 isKindOfClass:NSClassFromString(@"_UIBarBackgroundShadowContentImageView")]) {
obj3.hidden = YES;
}
}];
}
}];
}
}];
}
#pragma mark - other
// 处理超出区域点击无效的问题
- (UIView*)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
UIView *view = [super hitTest:point withEvent:event];
if (self.isHidden==NO) {
if (view == nil){
//转换坐标
CGPoint tempPoint = [self.centerBtn convertPoint:point fromView:self];
//判断点击的点是否在按钮区域内
if (CGRectContainsPoint(self.centerBtn.bounds, tempPoint)){
//返回按钮
return _centerBtn;
}
}
}
return view;
}
@end