猎豆优选

LDBulgeTabbarVC.m 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. //
  2. // LDBulgeTabbarVC.m
  3. // YouHuiProject
  4. //
  5. // Created by liuxueli on 2019/3/4.
  6. // Copyright © 2019 kuxuan. All rights reserved.
  7. //
  8. #import "LDBulgeTabbarVC.h"
  9. @interface LDBulgeTabbarVC ()<UITabBarControllerDelegate>
  10. @end
  11. @implementation LDBulgeTabbarVC
  12. - (void)viewDidLoad {
  13. [super viewDidLoad];
  14. _mcTabbar = [[LDTabbar alloc] init];
  15. [_mcTabbar.centerBtn addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
  16. //利用KVC 将自己的tabbar赋给系统tabBar
  17. [self setValue:_mcTabbar forKeyPath:@"tabBar"];
  18. self.delegate = self;
  19. }
  20. - (void)didReceiveMemoryWarning {
  21. [super didReceiveMemoryWarning];
  22. }
  23. // 重写选中事件, 处理中间按钮选中问题
  24. - (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{
  25. _mcTabbar.centerBtn.selected = (tabBarController.selectedIndex == self.viewControllers.count/2);
  26. if (self.mcDelegate){
  27. [self.mcDelegate mcTabBarController:tabBarController didSelectViewController:viewController];
  28. }
  29. }
  30. - (void)buttonAction:(UIButton *)button{
  31. NSInteger count = self.viewControllers.count;
  32. self.selectedIndex = count/2;//关联中间按钮
  33. [self tabBarController:self didSelectViewController:self.viewControllers[self.selectedIndex]];
  34. }
  35. @end