目前比较火的社交软件尤其是抖音等微视频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。
定制TabBar发布按钮
本文介绍如何在iOS应用中使用UITabBarController时,为中间的TabBar按钮定制一个特殊的发布按钮样式,并通过模态视图展示发布界面而非切换到新的ViewController。
4677

被折叠的 条评论
为什么被折叠?



