依赖于第三方的框架RESideMenu

1.AppDelegate.m中的实现

  1. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  2. // Override point for customization after application launch.
  3.  
  4. //在AppDelegate.h中声明属性,初始化tabBarController
  5. self.tabBar = [[UITabBarController alloc] init];
  6.  
  7. ViewController* vc1 = [[ViewController alloc] init];
  8. vc1.tabBarItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemBookmarks tag:];
  9. UINavigationController* nav1 = [[UINavigationController alloc] initWithRootViewController:vc1];
  10.  
  11. ViewController1* vc2 = [[ViewController1 alloc] init];
  12. vc2.tabBarItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemContacts tag:];
  13. UINavigationController* nav2 = [[UINavigationController alloc] initWithRootViewController:vc2];
  14.  
  15. self.tabBar.viewControllers = @[nav1,nav2];
  16.  
  17. //初始化leftVC
  18. LeftController* left = [[LeftController alloc] init];
  19.  
  20. //初始化RESideMenu
  21. RESideMenu* menu = [[RESideMenu alloc] initWithContentViewController:self.tabBar leftMenuViewController:left rightMenuViewController:nil];
  22. self.window.rootViewController= menu;
  23. return YES;
  24. }

2.left左侧菜单

  1. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  2. AppDelegate* GHDelegate = (AppDelegate* )[UIApplication sharedApplication].delegate;
  3. ViewController1_1* vc = [[ViewController1_1 alloc] init];
  4.  
  5. //通过GHDelegate.tabBar.selectedIndex获得当前tabbaritem对应的nav,进行页面跳转
  6. NSArray *arrControllers = GHDelegate.tabBar.viewControllers;
  7.  
  8. if (GHDelegate.tabBar.selectedIndex==) {
  9. UINavigationController* nav = (UINavigationController* )[arrControllers objectAtIndex:];
  10. //隐藏sideMenuViewController
  11. [self.sideMenuViewController hideMenuViewController];
  12. //隐藏底部
  13. vc.hidesBottomBarWhenPushed = YES;
  14. [nav pushViewController:vc animated:YES];
  15. }else{
  16. UINavigationController* nav = (UINavigationController* )[arrControllers objectAtIndex:];
  17. [self.sideMenuViewController hideMenuViewController];
  18. vc.hidesBottomBarWhenPushed = YES;
  19. [nav pushViewController:vc animated:YES];
  20. }
  21.  
  22. }

3.RESideMenu常见的属性设置

  1. - (void)awakeFromNib
  2. {
  3. self.parallaxEnabled = NO; //视图差效果
  4. self.scaleContentView = YES; //中心视图缩放功能打开
  5. self.contentViewScaleValue = 0.95; //侧滑出现时缩放比
  6. self.scaleMenuView = NO; //侧滑出来的视图是否支持缩放
  7. self.contentViewShadowEnabled = YES; //中心视图阴影效果,打开显得有层次感。
  8. self.contentViewShadowRadius = 4.5; //中心视图阴影效果Radius
  9. self.panGestureEnabled = NO; //关闭拖动支持手势
  10.  
  11. //使用storyboard初始化中心视图和左视图。
  12. self.contentViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"contentViewController"]; //tabbar controller
  13.  
  14. self.leftMenuViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"leftMenuViewController"];
  15. }

附件:

4.设置基本导航控制器

  1. #import "LHLNavigationViewController.h"
  2.  
  3. @interface LHLNavigationViewController () <UIGestureRecognizerDelegate>
  4.  
  5. @end
  6.  
  7. @implementation LHLNavigationViewController
  8.  
  9. + (void)load
  10. {
  11. UINavigationBar *navBar = [UINavigationBar appearanceWhenContainedIn:self, nil];
  12. // 设置导航条字体
  13. NSMutableDictionary *attr = [NSMutableDictionary dictionary];
  14. attr[NSFontAttributeName] = [UIFont systemFontOfSize:];
  15. [navBar setTitleTextAttributes:attr];
  16.  
  17. // 设置背景图片
  18. [navBar setBackgroundImage:[UIImage imageNamed:@"navigationbarBackgroundWhite"] forBarMetrics:UIBarMetricsDefault];
  19. }
  20.  
  21. - (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated{
  22.  
  23. if (self.childViewControllers.count > ) { // 非根控制器
        // 自定义UIBarButtonItem的分类方法
  24. UIBarButtonItem *item = [UIBarButtonItem backItemWitnImage:[UIImage imageNamed:@"navigationButtonReturn"] heighlightImage:[UIImage imageNamed:@"navigationButtonReturnClick"] target:self action:@selector(back) title:@"返回"];
  25. viewController.hidesBottomBarWhenPushed = YES;
  26. viewController.navigationItem.leftBarButtonItem = item;
  27. }
  28.  
  29. [super pushViewController:viewController animated:animated];
  30.  
  31. }
  32.  
  33. - (void)back
  34. {
  35. [self popViewControllerAnimated:YES];
  36. }
  37.  
  38. - (void)viewDidLoad {
  39. [super viewDidLoad];

  40.   // 全屏返回手势
  41. UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self.interactivePopGestureRecognizer.delegate action:@selector(handleNavigationTransition:)];
  42. pan.delegate = self;
  43. self.interactivePopGestureRecognizer.enabled = NO;
  44. [self.view addGestureRecognizer:pan];
  45.  
  46. }
  47. /*
  48. <UIScreenEdgePanGestureRecognizer: 0x7f7f98c97430;
  49. state = Possible; delaysTouchesBegan = YES;
  50. view = <UILayoutContainerView 0x7f7f98f19d00>;
  51. target= <(action=handleNavigationTransition:,
  52. target=<_UINavigationInteractiveTransition 0x7f7f98c96ee0>)>
  53. */
  54.  
  55. #pragma mark - UIGestureRecognizerDelegate
  56. - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
  57. {
  58. return self.childViewControllers.count > ;
  59. }
  60.  
  61. - (void)didReceiveMemoryWarning {
  62. [super didReceiveMemoryWarning];
  63. // Dispose of any resources that can be recreated.
  64. }
  65.  
  66. @end

5.设置UITabBarViewController

  1. #import "LHLTabBarController.h"
  2. #import "LHLEssenceViewController.h"
  3. #import "LHLFriendTrendViewController.h"
  4. #import "LHLMeViewController.h"
  5. #import "LHLNewViewController.h"
  6. #import "LHLPublishViewController.h"
  7. #import "LHLTabBar.h"
  8. #import "LHLNavigationViewController.h"
  9.  
  10. @interface LHLTabBarController ()
  11.  
  12. @end
  13.  
  14. @implementation LHLTabBarController
  15.  
  16. // load方法只会调用一次
  17. + (void)load
  18. {
  19. // 设置某个类中的 UITabBarItem 按钮的颜色
  20. UITabBarItem *item = [UITabBarItem appearanceWhenContainedIn:self, nil];
  21. NSMutableDictionary *attrs = [NSMutableDictionary dictionary];
  22. attrs[NSForegroundColorAttributeName] = [UIColor blackColor];
  23. [item setTitleTextAttributes:attrs forState:UIControlStateSelected];
  24.  
  25. // 设置字体的尺寸:只有正常状态下设置才有效果
  26. NSMutableDictionary *attrsNor = [NSMutableDictionary dictionary];
  27. attrsNor[NSFontAttributeName] = [UIFont systemFontOfSize:];
  28. [item setTitleTextAttributes:attrsNor forState:UIControlStateNormal];
  29. }
  30.  
  31. #pragma mark - 初始化
  32. - (void)viewDidLoad {
  33. [super viewDidLoad];
  34.  
  35. // 1.创建所有子控制器
  36. [self setUpAllChildControllers];
  37.  
  38. // 2.2设置tabBar按钮的标题
  39. [self setUpAllTitles];
  40.  
  41. // 3.使用自定义tabBar
  42. [self setUpTabBar];
  43.  
  44. }
  45.  
  46. #pragma mark - 自定义方法
  47. - (void)setUpAllChildControllers
  48. {
  49. // 2.1.设置tabBar的子控制器
  50. // 精华
  51. LHLEssenceViewController *essenceVC = [[LHLEssenceViewController alloc] init];
  52. LHLNavigationViewController *nav = [[LHLNavigationViewController alloc] initWithRootViewController:essenceVC];
  53. [self addChildViewController:nav];
  54.  
  55. // 新帖
  56. LHLNewViewController *newVC = [[LHLNewViewController alloc] init];
  57. LHLNavigationViewController *nav1 = [[LHLNavigationViewController alloc] initWithRootViewController:newVC];
  58. [self addChildViewController:nav1];
  59.  
  60. // 关注
  61. LHLFriendTrendViewController *trendVC = [[LHLFriendTrendViewController alloc] init];
  62. LHLNavigationViewController *nav3 = [[LHLNavigationViewController alloc] initWithRootViewController:trendVC];
  63. [self addChildViewController:nav3];
  64.  
  65. // 我
  66. LHLMeViewController *meVC = [[LHLMeViewController alloc] init];
  67. LHLNavigationViewController *nav4 = [[LHLNavigationViewController alloc] initWithRootViewController:meVC];
  68. [self addChildViewController:nav4];
  69.  
  70. }
  71.  
  72. - (void)setUpAllTitles
  73. {
  74. // 精华
  75. UINavigationController *nav = self.childViewControllers[];
  76. [self setTitleButton:nav title:@"精华" image:@"tabBar_essence_icon" selectImage:@"tabBar_essence_click_icon"];
  77.  
  78. // 新帖
  79. UINavigationController *nav1 = self.childViewControllers[];
  80. [self setTitleButton:nav1 title:@"新帖" image:@"tabBar_new_icon" selectImage:@"tabBar_new_click_icon"];
  81.  
  82. // 关注
  83. UINavigationController *nav3 = self.childViewControllers[];
  84. [self setTitleButton:nav3 title:@"关注" image:@"tabBar_friendTrends_icon" selectImage:@"tabBar_friendTrends_click_icon"];
  85.  
  86. // 我
  87. UINavigationController *nav4 = self.childViewControllers[];
  88. [self setTitleButton:nav4 title:@"我" image:@"tabBar_me_icon" selectImage:@"tabBar_me_click_icon"];
  89. }
  90.  
  91. - (void)setTitleButton:(UINavigationController *)nav title:(NSString *)aTitle image:(NSString *)aImage selectImage:(NSString *)aSelectImage
  92. {
  93. nav.tabBarItem.title = aTitle;
  94. nav.tabBarItem.image = [UIImage imageRenderOriginalWithName:aImage];
  95. nav.tabBarItem.selectedImage = [UIImage imageRenderOriginalWithName:aSelectImage];
  96. }
  97.  
  98. - (void)setUpTabBar
  99. {
  100. LHLTabBar *tabBar = [[LHLTabBar alloc] init];
  101. // 利用KVC对系统的tabBar进行赋值: KVC的原理是通过访问属性进行赋值,不是通过setter方法进行赋值
  102. [self setValue:tabBar forKeyPath:@"tabBar"];
  103. }
  104.  
  105. @end

6.分类文件

UIBarButtonItem

  1. #import "UIBarButtonItem+item.h"
  2.  
  3. @implementation UIBarButtonItem (item)
  4. + (UIBarButtonItem *)itemWitnImage:(UIImage *)aImage heighlightImage:(UIImage *)aSelectImage target:(id)aTarget action:(SEL)aAction
  5. {
  6. UIButton *btn = [[UIButton alloc] init];
  7. [btn setImage:aImage forState:UIControlStateNormal];
  8. [btn setImage:aSelectImage forState:UIControlStateHighlighted];
  9. [btn sizeToFit];
  10. [btn addTarget:aTarget action:aAction forControlEvents:UIControlEventTouchUpInside];
  11. // 添加的代码
  12. UIView *itemView = [[UIView alloc] initWithFrame:btn.bounds];
  13. [itemView addSubview:btn];
  14.  
  15. return [[UIBarButtonItem alloc] initWithCustomView:itemView];
  16. }
  17.  
  18. + (UIBarButtonItem *)itemWitnImage:(UIImage *)aImage selectedImage:(UIImage *)aSelectImage target:(id)aTarget action:(SEL)aAction
  19. {
  20. UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
  21. [btn setImage:aImage forState:UIControlStateNormal];
  22. [btn setImage:aSelectImage forState:UIControlStateSelected];
  23. [btn sizeToFit];
  24. [btn addTarget:aTarget action:aAction forControlEvents:UIControlEventTouchUpInside];
  25. UIView *containerView = [[UIView alloc] initWithFrame:btn.bounds];
  26. [containerView addSubview:btn];
  27. return [[UIBarButtonItem alloc] initWithCustomView:containerView];
  28. }
  29.  
  30. + (UIBarButtonItem *)backItemWitnImage:(UIImage *)aImage heighlightImage:(UIImage *)aSelectImage target:(id)aTarget action:(SEL)aAction title:(NSString *)aTitle
  31. {
  32. UIButton *btn = [[UIButton alloc] init];
  33. [btn setImage:aImage forState:UIControlStateNormal];
  34. [btn setImage:aSelectImage forState:UIControlStateHighlighted];
  35. [btn setTitle:aTitle forState:UIControlStateNormal];
  36. [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  37. [btn setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted];
  38. btn.contentEdgeInsets = UIEdgeInsetsMake(, -, , );
  39. [btn sizeToFit];
  40. [btn addTarget:aTarget action:aAction forControlEvents:UIControlEventTouchUpInside];
  41. UIView *containerView = [[UIView alloc] initWithFrame:btn.bounds];
  42. [containerView addSubview:btn];
  43. return [[UIBarButtonItem alloc] initWithCustomView:containerView];
  44. }
  45.  
  46. @end

UIImae

  1. #import "UIImage+image.h"
  2.  
  3. @implementation UIImage (image)
  4. // 在周边加一个边框为1的透明像素
  5. - (UIImage *)imageAntialias
  6. {
  7. CGFloat border = 1.0f;
  8. CGRect rect = CGRectMake(border, border, self.size.width-*border, self.size.height-*border);
  9.  
  10. UIImage *img = nil;
  11.  
  12. UIGraphicsBeginImageContext(CGSizeMake(rect.size.width,rect.size.height));
  13. [self drawInRect:CGRectMake(-, -, self.size.width, self.size.height)];
  14. img = UIGraphicsGetImageFromCurrentImageContext();
  15. UIGraphicsEndImageContext();
  16.  
  17. UIGraphicsBeginImageContext(self.size);
  18. [img drawInRect:rect];
  19. UIImage* antiImage = UIGraphicsGetImageFromCurrentImageContext();
  20. UIGraphicsEndImageContext();
  21.  
  22. return antiImage;
  23. }
  24. // 返回一张没有被渲染的图片
  25. + (UIImage *)imageRenderOriginalWithName:(NSString *)imageName
  26. {
  27. UIImage *image = [UIImage imageNamed:imageName];
  28. image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
  29. return image;
  30. }
  31.  
  32. @end

7.UITabBar

  1. #import "LHLTabBar.h"
  2.  
  3. @interface LHLTabBar ()
  4.  
  5. @property (nonatomic, weak) UIButton *plusButton;
  6.  
  7. @end
  8.  
  9. @implementation LHLTabBar
  10.  
  11. - (UIButton *)plusButton{
  12. if (_plusButton == nil) {
  13. UIButton *plusButton = [UIButton buttonWithType:UIButtonTypeCustom];
  14. [plusButton setBackgroundImage:[UIImage imageNamed:@"tabBar_publish_icon"] forState:UIControlStateNormal];
  15. [plusButton setBackgroundImage:[UIImage imageNamed:@"tabBar_publish_click_icon"] forState:UIControlStateHighlighted];
  16. [plusButton sizeToFit];
  17. [self addSubview:plusButton];
  18. _plusButton = plusButton;
  19. }
  20. return _plusButton;
  21. }
  22.  
  23. - (void)layoutSubviews
  24. {
  25. [super layoutSubviews];
  26.  
  27. // 布局子控件
  28. NSInteger count = self.items.count + ;
  29. CGFloat btnW = self.lhl_width / count;
  30. CGFloat btnH = self.lhl_height;
  31.  
  32. NSInteger i = ;
  33. for (UIButton *tabBarButton in self.subviews) {
  34. // 取出UITabBarButton
  35. if ([tabBarButton isKindOfClass:NSClassFromString(@"UITabBarButton")]) {
  36. if (i == ) {
  37. i += ;
  38. }
  39. tabBarButton.frame = CGRectMake(btnW * i, , btnW, btnH);
  40. i++;
  41. }
  42. // 隐藏tabBar黑线
  43. NSString *subFrames = NSStringFromCGRect(tabBarButton.frame);
  44. NSString *blackLine = @"{{0, -0.5}, {375, 0.5}}";
  45. if ([subFrames isEqualToString:blackLine]) {
  46. tabBarButton.hidden = YES;
  47. }
  48.  
  49. }
  50. // plusButton
  51. self.plusButton.center = CGPointMake(self.lhl_width * 0.5, self.frame.size.height * 0.5);
  52.  
  53. }
  54.  
  55. @end

第六篇、抽屉效果+UITabBarController(主流框架)的更多相关文章

  1. 第六篇:web之python框架之django

    python框架之django   python框架之django 本节内容 web框架 mvc和mtv模式 django流程和命令 django URL django views django te ...

  2. iOS开发——UI进阶篇(十三)UITabBarController简单使用,qq主流框架

    一.UITabBarController简单使用 // 程序加载完毕 - (BOOL)application:(UIApplication *)application didFinishLaunchi ...

  3. iOS开发——实用技术OC篇&简单抽屉效果的实现

    简单抽屉效果的实现 就目前大部分App来说基本上都有关于抽屉效果的实现,比如QQ/微信等.所以,今天我们就来简单的实现一下.当然如果你想你的效果更好或者是封装成一个到哪里都能用的工具类,那就还需要下一 ...

  4. iOS开发——高级篇——iOS抽屉效果实现原理

    实现一个简单的抽屉效果: 核心思想:KVO实现监听mainV的frame值的变化 核心代码: #import "ViewController.h" // @"frame& ...

  5. 搭建App主流框架_纯代码搭建(OC)

    转载自:http://my.oschina.net/hejunbinlan/blog/529778?fromerr=EmSuX7PR 搭建主流框架界面 源码地址在文章末尾 达成效果 效果图 注:本文部 ...

  6. 10分钟搭建 App 主流框架

    搭建主流框架界面 0.达成效果 我们玩iPhone应用的时候,有没发现大部分的应用都是上图差不多的结构,下面的TabBar控制器可以切换子控制器,上面又有Navigation导航条 我们本文主要是搭建 ...

  7. python三大web框架Django,Flask,Flask,Python几种主流框架,13个Python web框架比较,2018年Python web五大主流框架

    Python几种主流框架 从GitHub中整理出的15个最受欢迎的Python开源框架.这些框架包括事件I/O,OLAP,Web开发,高性能网络通信,测试,爬虫等. Django: Python We ...

  8. 第六篇 ANDROID窗口系统机制之显示机制

    第六篇 ANDROID窗口系统机制之显示机制 ANDROID的显示系统是整个框架中最复杂的系统之一,涉及包括窗口管理服务.VIEW视图系统.SurfaceFlinger本地服务.硬件加速等.窗口管理服 ...

  9. 十分钟搭建App主流框架

    搭建主流框架界面 0.达成效果 Snip20150904_5.png 我们玩iPhone应用的时候,有没发现大部分的应用都是上图差不多的结构,下面的TabBar控制器可以切换子控制器,上面又有Navi ...

随机推荐

  1. UML精粹学习 - 订单类结构图

    Order Class Diagram of Martin Fowler's UML Distilled

  2. 多个非同源的shared_ptr管理对象引起double free

    有多个不同源的shared_ptr管理对象时会出现多次释放对象,这里不同源是指多组间不是通过拷贝构造.复制等手段而来的,即几组shared_ptr是独立声明的. #include<iostrea ...

  3. OverHust

    https://github.com/fanhongwei/OverHust https://github.com/eltld/OverHust

  4. ajax开发框架和XMLhttpRequest、responseText、responseXml和JSON的应用

    1 AJAX开发框架 2 A 初始化XMLHttpRequest对象 3 B指定响应处理函数 4 C发出HTTP请求 5 D处理服务器返回的信息 6 数据格式提要 6 优点 6 缺点 7 解析 JSO ...

  5. 【Backbone】简介

    1.Model 2.Collection 3.View 4.Router 5.History 6.Events http://addyosmani.github.io/backbone-fundame ...

  6. C#使用Monitor类、Lock和Mutex类进行多线程同步

    在多线程中,为了使数据保持一致性必须要对数据或是访问数据的函数加锁,在数据库中这是很常见的,但是在程序中由于大部分都是单线程的程序,所以没有加锁的必要,但是在多线程中,为了保持数据的同步,一定要加锁, ...

  7. L - Abbott's Revenge(比较复杂的bfs)

    Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Status Practice UV ...

  8. [Java] Servlet 3 —— 用Java生成GET/POST请求

    Servlet是SUN指定的Java服务器端编程规范,用以处理来自客户端的请求,处理并做出响应的一套基础API.Servlet是运行在 Servlet容器中的Java小程序,容器运行在服务器端,服务器 ...

  9. [经典算法] 排列组合-N元素集合的所有子集(二)

    题目说明: 给定一组数字或符号,按照字典序产生所有可能的集合(包括空集合),例如给定1 2 3,则可能的集合为:{}.{1}.{1,2}.{1,2,3}.{1,3}.{2}.{2,3}.{3}. 题目 ...

  10. Visual Studio 扩展包(.vsix)制作

    前言:上篇介绍了 Visual Studio扩展工具添加与卸载,本编要介绍的是Visual Studio 扩展包(.vsix)的制作. 方法: ①.下载并安装Visual Studio 2010 SD ...