完全定制UITabBarViewController

效果

 

源码

https://github.com/YouXianMing/iOS-Project-Examples 中的 TotalCustomTabBarController

//
// CustomTabBarViewController.h
// TotalCustomTabBarController
//
// Created by YouXianMing on 16/6/2.
// Copyright © 2016年 YouXianMing. All rights reserved.
// #import "CustomViewController.h"
@class CustomTabBarViewController; @protocol CustomTabBarViewControllerDelegate <NSObject> @optional - (BOOL)customTabBarController:(CustomTabBarViewController *)tabBarController
shouldSelectViewController:(UIViewController *)viewController
selectedIndex:(NSInteger)index; - (void)customTabBarController:(CustomTabBarViewController *)tabBarController
didSelectViewController:(UIViewController *)viewController
selectedIndex:(NSInteger)index; @end @interface CustomTabBarViewController : CustomViewController /**
* CustomTabBarViewController's delegate.
*/
@property (nonatomic, weak) id <CustomTabBarViewControllerDelegate> delegate; /**
* TabBar's height, default is 49.f.
*/
@property (nonatomic) CGFloat tabBarHeight; /**
* The controller's index that loaded and show by CustomTabBarViewController at the first time.
*/
@property (nonatomic) NSInteger firstLoadIndex; /**
* ViewControllers.
*/
@property(nonatomic, strong) NSArray <__kindof CustomViewController *> *viewControllers; /**
* Hide TabBarView or not.
*
* @param hide Hide or not.
* @param animated Animated or not.
*/
- (void)hideTabBarView:(BOOL)hide animated:(BOOL)animated; #pragma mark - Used by subClass. /**
* TabBarView, you should add view on it.
*/
@property (nonatomic, strong, readonly) UIView *tabBarView; /**
* Will select index, used by subClass.
*
* @param index Index.
*
* @return Will selected or not.
*/
- (BOOL)willSelectIndex:(NSInteger)index; /**
* Did selected index, used by subClass.
*
* @param index Index.
*/
- (void)didSelectedIndex:(NSInteger)index; /**
* Build items in the tabBarView.
*/
- (void)buildItems; @end
//
// CustomTabBarViewController.m
// TotalCustomTabBarController
//
// Created by YouXianMing on 16/6/2.
// Copyright © 2016年 YouXianMing. All rights reserved.
// #import "CustomTabBarViewController.h" @interface CustomTabBarViewController () @property (nonatomic, strong) UIView *contentView;
@property (nonatomic, strong) UIView *tabBarView; @property (nonatomic, weak) UIViewController *currentViewController; @end @implementation CustomTabBarViewController - (instancetype)init { if (self = [super init]) { _tabBarHeight = .f;
_firstLoadIndex = ;
} return self;
} - (void)setup { [super setup]; // Add controller's view.
self.contentView = [[UIView alloc] initWithFrame:self.view.bounds];
[self.view addSubview:self.contentView]; // Add tabBarView.
self.tabBarView = [[UIView alloc] initWithFrame:CGRectMake(, self.view.frame.size.height - _tabBarHeight,
self.view.frame.size.width, _tabBarHeight)];
[self.view addSubview:self.tabBarView]; // Add ChildViewController.
for (int i = ; i < self.viewControllers.count; i++) { CustomViewController *customViewController = self.viewControllers[i];
[self addChildViewController:customViewController];
} // Build items.
[self buildItems]; // Load first show controller.
[self.viewControllers[_firstLoadIndex] didMoveToParentViewController:self];
[self.contentView addSubview:self.viewControllers[_firstLoadIndex].view];
self.currentViewController = self.viewControllers[_firstLoadIndex];
[self didSelectedIndex:_firstLoadIndex];
} - (void)buildItems { // Overwrite by subClass.
} - (BOOL)willSelectIndex:(NSInteger)index { if (self.delegate && [self.delegate respondsToSelector:@selector(customTabBarController:shouldSelectViewController:selectedIndex:)]) { return [self.delegate customTabBarController:self shouldSelectViewController:self.viewControllers[index] selectedIndex:index]; } else { return YES;
}
} - (void)didSelectedIndex:(NSInteger)index { if (self.delegate && [self.delegate respondsToSelector:@selector(customTabBarController:didSelectViewController:selectedIndex:)]) { [self.delegate customTabBarController:self didSelectViewController:self.viewControllers[index] selectedIndex:index];
} if ([self.currentViewController isEqual:self.viewControllers[index]]) { return;
} [self transitionFromViewController:self.currentViewController toViewController:self.viewControllers[index] duration:
options:UIViewAnimationOptionTransitionNone
animations:nil completion:^(BOOL finished) { self.currentViewController = self.viewControllers[index];
}];
} - (void)hideTabBarView:(BOOL)hide animated:(BOOL)animated { CGRect frame = self.tabBarView.frame;
CGFloat duration = 0.5f; if (hide) { if (animated) { [UIView animateWithDuration:duration delay: usingSpringWithDamping: initialSpringVelocity: options:UIViewAnimationOptionBeginFromCurrentState animations:^{ self.tabBarView.frame = CGRectMake(, self.view.bounds.size.height, frame.size.width, frame.size.height);
self.tabBarView.alpha = .f; } completion:nil]; } else { self.tabBarView.frame = CGRectMake(, self.view.bounds.size.height, frame.size.width, frame.size.height);
self.tabBarView.alpha = .f;
} } else { if (animated) { [UIView animateWithDuration:duration delay: usingSpringWithDamping: initialSpringVelocity: options:UIViewAnimationOptionBeginFromCurrentState animations:^{ self.tabBarView.frame = CGRectMake(, self.view.bounds.size.height - frame.size.height,
frame.size.width, frame.size.height);
self.tabBarView.alpha = .f; } completion:nil]; } else { self.tabBarView.frame = CGRectMake(, self.view.bounds.size.height - frame.size.height,
frame.size.width, frame.size.height);
self.tabBarView.alpha = .f;
}
}
} - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated];
} @end

说明

详细细节请参考演示项目,定制按钮需要继承控制器,在重载buildItems方法中添加相关事件即可。

完全定制UITabBarViewController的更多相关文章

  1. ASP.NET Core应用的错误处理[3]:ExceptionHandlerMiddleware中间件如何呈现“定制化错误页面”

    DeveloperExceptionPageMiddleware中间件利用呈现出来的错误页面实现抛出异常和当前请求的详细信息以辅助开发人员更好地进行纠错诊断工作,而ExceptionHandlerMi ...

  2. Webstorm+Webpack+echarts构建个性化定制的数据可视化图表&&两个echarts详细教程(柱状图,南丁格尔图)

    Webstorm+Webpack+echarts   ECharts 特性介绍 ECharts,一个纯 Javascript 的图表库,可以流畅的运行在 PC 和移动设备上,兼容当前绝大部分浏览器(I ...

  3. 标准产品+定制开发:专注打造企业OA、智慧政务云平台——山东森普软件,交付率最高的技术型软件公司

    一.公司简介山东森普信息技术有限公司(以下简称森普软件)是一家专门致力于移动互联网产品.企业管理软件定制开发的技术型企业.公司总部设在全国五大软件园之一的济南齐鲁软件园.森普SimPro是由Simpl ...

  4. Gradle 实现 Android 多渠道定制化打包

    Gradle 实现 Android 多渠道定制化打包 版权声明:本文为博主原创文章,未经博主允许不得转载. 最近在项目中遇到需要实现 Apk 多渠道.定制化打包, Google .百度查找了一些资料, ...

  5. Xamarin+Prism小试牛刀:定制跨平台Outlook邮箱应用(后续)

    在[Xamarin+Prism小试牛刀:定制跨平台Outlook邮箱应用]里面提到了Microsoft 身份认证,其实这也是一大块需要注意的地方,特作为后续补充这些知识点.上章是使用了Microsof ...

  6. Django admin定制化,User字段扩展[原创]

    前言 参考上篇博文,我们利用了OneToOneField的方式使用了django自带的user,http://www.cnblogs.com/caseast/p/5909248.html , 但这么用 ...

  7. 用Kotlin实现Android定制视图(KAD 06)

    作者:Antonio Leiva 时间:Dec 27, 2016 原文链接:https://antonioleiva.com/custom-views-android-kotlin/ 在我们阅读有关c ...

  8. CSharpGL(28)得到高精度可定制字形贴图的极简方法

    CSharpGL(28)得到高精度可定制字形贴图的极简方法 回顾 以前我用SharpFont实现了解析TTF文件从而获取字形贴图的功能,并最终实现了用OpenGL渲染文字. 使用SharpFont,美 ...

  9. 不懂CSS也能定制博客界面!

    之前没想过定制博客界面,毕竟CSS,HTML什么的都不懂,不过看了这篇文章分分钟搞定: [详细图解]一步一步教你自定义博客园(cnblog)界面 我是基于模板BlueSky做了些改动,先看修改前后的效 ...

随机推荐

  1. ***在PHP语言中使用JSON和将json还原成数组(json_decode()的常见错误)

    在之前我写过php返回json数据简单实例,刚刚上网,突然发现一篇文章,也是介绍json的,还挺详细,值得参考.内容如下 从5.2版本开始,PHP原生提供json_encode()和json_deco ...

  2. NET-知识点:C#中Equals和==比较

    第一.相等性比较 其实这个问题的的本质就是C#的相等比较,相等比较可以分两类: 1.引用相等性,引用相等性指两个对象引用均引用同一基础对象. 2.值相等性,值相等性指两个对象包含相同的一个或多个值,其 ...

  3. tidb 升级步骤

    1.检查ansible版本,正常情况下,2.1 rc3需要兼容ansible 2.5以上的版本 $ ansible --version 2.检查python两个模块jinja2需要升级到2.9.6或以 ...

  4. json字符串的标准格式

    现在越来越多的项目和开发插件等默认都会支持和使用json数据格式,作为数据保持.传输的一种方式. 说是其中一种,就标示还有好多其他格式.比如:最多是xml.webservice的标准数据格式. 不过由 ...

  5. UVALive - 6709

    二维线段树单点修改板子题 #include<bits/stdc++.h> #define LL long long #define fi first #define se second # ...

  6. Linux详细安装步骤

    Linux详细安装步骤(CentOS_6.7_64位) 1.先安装好VMware10软件 2.验证VM是否安装成功: (有些机器在安装vmware的时候会出现一个错误:virtual XT,这需要重启 ...

  7. select 详解

    In summary, a socket will be identified in a particular set when select returns if: readfds:If liste ...

  8. 黑马程序员_java基础笔记(14)...交通灯管理系统_编码思路及代码

    —————————— ASP.Net+Android+IOS开发..Net培训.期待与您交流! —————————— 1,面试题——交通灯管理系统 模拟实现十字路口的交通灯管理系统逻辑,具体需求如下: ...

  9. 000 在什么位置写js代码

    一:介绍 1.DOM 2.节点分类 节点及其类型: 1). 元素节点 2). 属性节点: 元素的属性, 可以直接通过属性的方式来操作. 3). 文本节点: 是元素节点的子节点, 其内容为文本. 二:J ...

  10. 【Android Studio】为Android Studio设置HTTP代理

    [Android Studio]为Android Studio设置HTTP代理   大陆的墙很厚很高,初次安装Android Studio下载SDK等必定失败,设置代理方法如下: 1. 到androi ...