实现tabbar发布按钮个性化弹出功能

目前比较火的社交软件尤其是抖音等微视频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。

猜你喜欢

转载自blog.csdn.net/lidongxuedecsdn/article/details/80607296
今日推荐