iOS学习笔记-094.彩票09——隐藏底部tabar和统一设置返回按钮

来源:互联网 发布:java使用md5加密解密 编辑:程序博客网 时间:2024/05/17 04:01

  • 彩票09隐藏底部tabar和统一设置返回按钮
    • 一图示
    • 二隐藏底部tabar分析
    • 三隐藏底部tabar实现
      • 1 QWMTabBarViewControllerm 修改
      • 2 给全部采种设置 push 的时候隐藏tabar
    • 四统一设置返回按钮分析
    • 五统一设置返回按钮实现

彩票09——隐藏底部tabar和统一设置返回按钮

一、图示

这里写图片描述


二、隐藏底部tabar分析

系统可以显示隐藏tabar的功能,如果我们自己移除,自己来搞那么会很麻烦,所以我们不能使用我们之前直接删除系统tabar的方式,我们应该选择在原来的系统tabar上添加我们的tabar。

第二、如果我们使用上面的方式添加到系统tabar中,我们会发现,系统tabar上面的按钮又会显示出来,覆盖在我们自定义的tabar上面。那么我们怎么搞呢?我们的做法就是,在自定义的 QWMTabBarViewController中,将要显示tabar的时候,移除系统的按钮,那么我们自定义的按钮,就能显示出来。但是系统按钮是私有的,我们无法判断。因此我们可以采用才判断是不是我们添加的控件,如果不是那么删除。

移除UITabBarButton(私有的控件)的3种方法 如下

  //1.移除系统的TabBar中的所有子空间,添加自己的子控件  for (UIView *view in self.tabBar.subviews) {      // 1.将类名转换成字符串,对比前缀,如果前缀是以UITabBar开头的,我们就移除      NSString *classString = NSStringFromClass([view class]);      if ([classString hasPrefix:@"UITabBar"]) {          [view removeFromSuperview];      }    //2.看一下这个类的父类是什么东西,子类敲不出来,看看父类能不能敲出来      NSLog(@"-- %@",view.superclass);      if ([view isKindOfClass:[UIColor class]]) {          [view removeFromSuperview];      }      // 3.判断是不是我们自己添加的类,如果不是自己添加的类就移除      if (![view isKindOfClass:[QWMTabBar class]]) {          [view removeFromSuperview];      }  }

三、隐藏底部tabar实现

3.1 QWMTabBarViewController.m 修改

修改两个地方,
>

  1. 把我们创建的tabar添加到系统tabar上,而不是移除

  2. -(void)viewWillAppear:(BOOL)animated中,移除系统的按钮 UITabBarButton

////  QWMTabBarViewController.m//  03_UIView79_彩票////  Created by 杞文明 on 17/7/24.//  Copyright © 2017年 杞文明. All rights reserved.//#import "QWMTabBarViewController.h"#import "QWMHallTableViewController.h"#import "QWMArenaViewController.h"#import "QWMDiscoverTableViewController.h"#import "QWMHistoryTableViewController.h"#import "QWMMyLotteryViewController.h"#import "QWMTabBar.h"#import "QWMNavigationController.h"#import "QWMArenaNavigationController.h"@interface QWMTabBarViewController ()<QWMTabBarDelegate>/** taBBar item 模型数组 */@property (nonatomic, strong) NSMutableArray *items;@end@implementation QWMTabBarViewController..........-(void)viewWillAppear:(BOOL)animated{    [super viewWillAppear:animated];//    NSLog(@"---viewWillAppear---");    // 移除系统的tabbar的子控件 UITabBarButton    // 逆向思维判断一下当前点控件是不是XMGTabBar,如果不是直接移除    for (UIView *view in self.tabBar.subviews) {        NSLog(@"%@",view);        if (![view isKindOfClass:[QWMTabBar class]]) {            [view removeFromSuperview];        }    }}-(void)setupTabBar{    //1.移除系统的TabBar    //[self.tabBar removeFromSuperview];    //2.添加自己的TabBar    QWMTabBar * tabBar = [[QWMTabBar alloc]init];    tabBar.items = self.items;    tabBar.frame = self.tabBar.bounds;    tabBar.backgroundColor = [UIColor redColor];    [self.tabBar addSubview:tabBar];    //设置代理    tabBar.delegate = self;}..........@end

3.2 给全部采种设置 push 的时候隐藏tabar

有两种方式创建

  1. 代码创建
vc.hidesBottomBarWhenPushed
  1. 图形界面设置

这里写图片描述


四、统一设置返回按钮分析

QWMNavigationController中在 push 控制器,我们判断当前的控制器是不是根控制器,如果不是,那么我们添加导航条左侧的按钮。点击按钮的时候 pop 控制器


五、统一设置返回按钮实现

主要操作两个地方

  1. -(void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated 中判断如果不是根控制器,那么添加放回按钮

  2. 给返回按钮添加 back 返回方法,这个方法干的事情是,pop 控制器

////  QWMNavigationController.m//  03_UIView79_彩票////  Created by 杞文明 on 17/8/13.//  Copyright © 2017年 杞文明. All rights reserved.//#import "QWMNavigationController.h"@interface QWMNavigationController ()/** 系统手势代理 */@property (nonatomic, strong) id popGesture;@end@implementation QWMNavigationController......-(void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated{    [super pushViewController:viewController animated:animated];    //非根控制器的时候设置导航条目左侧按钮    if(self.viewControllers.count >1){        //非根控制器,设置放回        viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageWithRenderOriginalName:@"NavBack"] style:UIBarButtonItemStylePlain target:self action:@selector(back)];    }}-(void)back{    [self popViewControllerAnimated:YES];}......@end
阅读全文
0 0
原创粉丝点击