目前比較火的社交軟件尤其是抖音等微視頻app,都是tabbar中間的發佈按鈕點擊後以模態視圖形式彈出相冊,相機等界面,而不是通過tabbar形式進去的,這時候要想實現這樣的效果可以進行如下設置。還是5個tabbar,但是在第三個中間的按鈕上覆蓋一個UI給出的樣式。
在UITabbarController類ViewDidLoad中添加如下代碼
//給中間的發佈按鈕一個特殊樣式
self.delegate = self;
UIImageView *tabbarView = [[UIImageView alloc] initWithFrame:CGRectMake((SCREEN_WIDTH - 61)/2, self.tabBar.frame.size.height - 61, 61, 61)];
tabbarView.backgroundColor = [UIColor redColor];
[self.tabBar addSubview:tabbarView];
實現代理方法
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {
if (viewController == self.viewControllers[2]) {
//點擊中間tabbarItem,不切換,讓當前頁面跳轉
PublishViewController *publishVC = [[PublishViewController alloc] init];
publishVC.hidesBottomBarWhenPushed = YES;
[tabBarController.selectedViewController presentViewController:publishVC animated:YES completion:nil];
return NO;
}
return YES;
}
即可實現理想效果,而不是跳進第三個tabbar。