YOUPAILCTabBar.m 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. //
  2. // YOUPAILCTabBar.m
  3. // LiveChat
  4. //
  5. // Created by 张灿 on 2018/4/12.
  6. // Copyright © 2018年 caicai. All rights reserved.
  7. //
  8. #import "YOUPAILCTabBar.h"
  9. @interface YOUPAILCTabBar()
  10. @property (nonatomic, weak) UIButton *youpaipcenterBtn;
  11. @property (nonatomic,weak) UIView* youpaipgreenView;
  12. @property (nonatomic,strong) UIImageView* youpaipimgV;
  13. @end
  14. @implementation YOUPAILCTabBar
  15. - (instancetype)initWithFrame:(CGRect)frame {
  16. if (self = [super initWithFrame:frame]) {
  17. //去掉半透明效果
  18. self.translucent = YES;
  19. //去掉TabBar的分割线
  20. //[self setBackgroundImage:[UIImage new]];
  21. //[self setShadowImage:[UIImage new]];
  22. //设置中间按钮图片和尺寸
  23. // _imgV = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 60, 68)];
  24. // _imgV.image = [UIImage imageNamed:@"vqu_images_home_default"];
  25. }
  26. return self;
  27. }
  28. - (void)youpaifupdateCenterBtn:(BOOL)flag{
  29. if (flag) {
  30. self.youpaipimgV.image = [UIImage imageNamed:@""];
  31. }else{
  32. // self.imgV.image = [UIImage imageNamed:@"vqu_images_home_default"];
  33. self.youpaipimgV.image = [UIImage imageNamed:@""];
  34. }
  35. }
  36. - (void)layoutSubviews {
  37. [super layoutSubviews];
  38. //系统自带的按钮类型是UITabBarButton,找出这些类型的按钮,然后重新排布位置,空出中间的位置
  39. Class class = NSClassFromString(@"UITabBarButton");
  40. NSInteger btnIndex = 0;
  41. NSInteger item = [LCSaveData getWhiteVersion] ? 5 : 5;
  42. for (UIView *btn in self.subviews) {//遍历tabbar的子控件
  43. if ([btn isKindOfClass:class]) {//如果是系统的UITabBarButton,那么就调整子控件位置,空出中间位置
  44. if (Is_iPhoneX) {
  45. btn.frame = CGRectMake(KScreenWidth/item*btnIndex, 0, KScreenWidth/item,49);
  46. }
  47. else{
  48. btn.frame = CGRectMake(KScreenWidth/item*btnIndex, 0, KScreenWidth/item,self.frame.size.height);
  49. }
  50. // if (Is_iPhoneX) {
  51. // btn.frame = CGRectMake(KScreenWidth/5*btnIndex, 0, KScreenWidth/4,49);
  52. // }
  53. // else{
  54. // btn.frame = CGRectMake(KScreenWidth/5*btnIndex, 0, KScreenWidth/5,self.frame.size.height);
  55. // }
  56. if (btnIndex==1) {
  57. //modify by leo
  58. /*
  59. UIImageView* imgV = [[UIImageView alloc]initWithFrame:CGRectMake(KScreenWidth*3/10-30, -11, 60, 60)];
  60. imgV.image = [UIImage imageNamed:@"vqu_images_tab_rankingbg1"];
  61. self.imgV = imgV;
  62. [btn addSubview:imgV];
  63. [btn sendSubviewToBack:imgV];
  64. */
  65. }
  66. // else if(btnIndex ==2)
  67. // {
  68. // //modify by leo ---fix ios 13 bug --20191009
  69. // [btn.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
  70. // UIImageView* imgV = [[UIImageView alloc]initWithFrame:CGRectMake(btn.frame.size.width/2-30,-20, 60,68)];
  71. // if (!(kAppDelegate.isDisplayVideoDynamicPage == 1 && [self.selectedItem.title isEqualToString:@"发现"])) {
  72. //// imgV.image = [UIImage imageNamed:@"vqu_images_home_default"];
  73. // imgV.image = [UIImage imageNamed:@""];
  74. // }
  75. // self.imgV = imgV;
  76. // [btn addSubview:imgV];
  77. // [btn sendSubviewToBack:imgV];
  78. // if (Is_iPhoneX) {
  79. // btn.frame = CGRectMake(KScreenWidth/5*btnIndex, -7, KScreenWidth/5,49);
  80. // }
  81. // else{
  82. // btn.frame = CGRectMake(KScreenWidth/5*btnIndex, -7, KScreenWidth/5,self.frame.size.height);
  83. // }
  84. //
  85. // }
  86. btnIndex++;
  87. }
  88. }
  89. }
  90. - (void)youpaifcenterBtnDidClick{
  91. if (self.block) {
  92. self.block();
  93. }
  94. }
  95. - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
  96. //判断当前手指是否点击到中间按钮上,如果是,则响应按钮点击,其他则系统处理
  97. //首先判断当前View是否被隐藏了,隐藏了就不需要处理了
  98. if (self.isHidden == NO) {
  99. //将当前tabbar的触摸点转换坐标系,转换到中间按钮的身上,生成一个新的点
  100. CGPoint newP = [self convertPoint:point toView:self.youpaipcenterBtn];
  101. //判断如果这个新的点是在中间按钮身上,那么处理点击事件最合适的view就是中间按钮
  102. if ( [self.youpaipcenterBtn pointInside:newP withEvent:event]) {
  103. return self.youpaipcenterBtn;
  104. }
  105. }
  106. return [super hitTest:point withEvent:event];
  107. }
  108. @end