123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- //
- // YOUPAILCTabBar.m
- // LiveChat
- //
- // Created by 张灿 on 2018/4/12.
- // Copyright © 2018年 caicai. All rights reserved.
- //
- #import "YOUPAILCTabBar.h"
- @interface YOUPAILCTabBar()
- @property (nonatomic, weak) UIButton *youpaipcenterBtn;
- @property (nonatomic,weak) UIView* youpaipgreenView;
- @property (nonatomic,strong) UIImageView* youpaipimgV;
- @end
- @implementation YOUPAILCTabBar
- - (instancetype)initWithFrame:(CGRect)frame {
- if (self = [super initWithFrame:frame]) {
-
- //去掉半透明效果
- self.translucent = YES;
- //去掉TabBar的分割线
- //[self setBackgroundImage:[UIImage new]];
- //[self setShadowImage:[UIImage new]];
- //设置中间按钮图片和尺寸
- // _imgV = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 60, 68)];
- // _imgV.image = [UIImage imageNamed:@"vqu_images_home_default"];
- }
- return self;
- }
- - (void)youpaifupdateCenterBtn:(BOOL)flag{
- if (flag) {
- self.youpaipimgV.image = [UIImage imageNamed:@""];
- }else{
- // self.imgV.image = [UIImage imageNamed:@"vqu_images_home_default"];
- self.youpaipimgV.image = [UIImage imageNamed:@""];
- }
-
- }
- - (void)layoutSubviews {
- [super layoutSubviews];
- //系统自带的按钮类型是UITabBarButton,找出这些类型的按钮,然后重新排布位置,空出中间的位置
- Class class = NSClassFromString(@"UITabBarButton");
- NSInteger btnIndex = 0;
- NSInteger item = [LCSaveData getWhiteVersion] ? 5 : 5;
- for (UIView *btn in self.subviews) {//遍历tabbar的子控件
- if ([btn isKindOfClass:class]) {//如果是系统的UITabBarButton,那么就调整子控件位置,空出中间位置
- if (Is_iPhoneX) {
- btn.frame = CGRectMake(KScreenWidth/item*btnIndex, 0, KScreenWidth/item,49);
- }
- else{
- btn.frame = CGRectMake(KScreenWidth/item*btnIndex, 0, KScreenWidth/item,self.frame.size.height);
- }
- // if (Is_iPhoneX) {
- // btn.frame = CGRectMake(KScreenWidth/5*btnIndex, 0, KScreenWidth/4,49);
- // }
- // else{
- // btn.frame = CGRectMake(KScreenWidth/5*btnIndex, 0, KScreenWidth/5,self.frame.size.height);
- // }
- if (btnIndex==1) {
- //modify by leo
- /*
- UIImageView* imgV = [[UIImageView alloc]initWithFrame:CGRectMake(KScreenWidth*3/10-30, -11, 60, 60)];
- imgV.image = [UIImage imageNamed:@"vqu_images_tab_rankingbg1"];
- self.imgV = imgV;
- [btn addSubview:imgV];
- [btn sendSubviewToBack:imgV];
- */
- }
- // else if(btnIndex ==2)
- // {
- // //modify by leo ---fix ios 13 bug --20191009
- // [btn.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
- // UIImageView* imgV = [[UIImageView alloc]initWithFrame:CGRectMake(btn.frame.size.width/2-30,-20, 60,68)];
- // if (!(kAppDelegate.isDisplayVideoDynamicPage == 1 && [self.selectedItem.title isEqualToString:@"发现"])) {
- //// imgV.image = [UIImage imageNamed:@"vqu_images_home_default"];
- // imgV.image = [UIImage imageNamed:@""];
- // }
- // self.imgV = imgV;
- // [btn addSubview:imgV];
- // [btn sendSubviewToBack:imgV];
- // if (Is_iPhoneX) {
- // btn.frame = CGRectMake(KScreenWidth/5*btnIndex, -7, KScreenWidth/5,49);
- // }
- // else{
- // btn.frame = CGRectMake(KScreenWidth/5*btnIndex, -7, KScreenWidth/5,self.frame.size.height);
- // }
- //
- // }
- btnIndex++;
- }
- }
- }
- - (void)youpaifcenterBtnDidClick{
- if (self.block) {
- self.block();
- }
- }
- - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
- //判断当前手指是否点击到中间按钮上,如果是,则响应按钮点击,其他则系统处理
- //首先判断当前View是否被隐藏了,隐藏了就不需要处理了
- if (self.isHidden == NO) {
- //将当前tabbar的触摸点转换坐标系,转换到中间按钮的身上,生成一个新的点
- CGPoint newP = [self convertPoint:point toView:self.youpaipcenterBtn];
- //判断如果这个新的点是在中间按钮身上,那么处理点击事件最合适的view就是中间按钮
- if ( [self.youpaipcenterBtn pointInside:newP withEvent:event]) {
- return self.youpaipcenterBtn;
- }
- }
-
- return [super hitTest:point withEvent:event];
- }
- @end
|