1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- //
- // LDBulgeTabbarVC.m
- // YouHuiProject
- //
- // Created by liuxueli on 2019/3/4.
- // Copyright © 2019 kuxuan. All rights reserved.
- //
- #import "LDBulgeTabbarVC.h"
- @interface LDBulgeTabbarVC ()<UITabBarControllerDelegate>
- @end
- @implementation LDBulgeTabbarVC
- - (void)viewDidLoad {
- [super viewDidLoad];
- _mcTabbar = [[LDTabbar alloc] init];
- [_mcTabbar.centerBtn addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
- //利用KVC 将自己的tabbar赋给系统tabBar
- [self setValue:_mcTabbar forKeyPath:@"tabBar"];
- self.delegate = self;
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- }
- // 重写选中事件, 处理中间按钮选中问题
- - (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{
-
- _mcTabbar.centerBtn.selected = (tabBarController.selectedIndex == self.viewControllers.count/2);
-
- if (self.mcDelegate){
- [self.mcDelegate mcTabBarController:tabBarController didSelectViewController:viewController];
- }
- }
- - (void)buttonAction:(UIButton *)button{
- NSInteger count = self.viewControllers.count;
- self.selectedIndex = count/2;//关联中间按钮
- [self tabBarController:self didSelectViewController:self.viewControllers[self.selectedIndex]];
- }
- @end
|