完全定制UITabBarViewController
完全定制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的更多相关文章
- ASP.NET Core应用的错误处理[3]:ExceptionHandlerMiddleware中间件如何呈现“定制化错误页面”
DeveloperExceptionPageMiddleware中间件利用呈现出来的错误页面实现抛出异常和当前请求的详细信息以辅助开发人员更好地进行纠错诊断工作,而ExceptionHandlerMi ...
- Webstorm+Webpack+echarts构建个性化定制的数据可视化图表&&两个echarts详细教程(柱状图,南丁格尔图)
Webstorm+Webpack+echarts ECharts 特性介绍 ECharts,一个纯 Javascript 的图表库,可以流畅的运行在 PC 和移动设备上,兼容当前绝大部分浏览器(I ...
- 标准产品+定制开发:专注打造企业OA、智慧政务云平台——山东森普软件,交付率最高的技术型软件公司
一.公司简介山东森普信息技术有限公司(以下简称森普软件)是一家专门致力于移动互联网产品.企业管理软件定制开发的技术型企业.公司总部设在全国五大软件园之一的济南齐鲁软件园.森普SimPro是由Simpl ...
- Gradle 实现 Android 多渠道定制化打包
Gradle 实现 Android 多渠道定制化打包 版权声明:本文为博主原创文章,未经博主允许不得转载. 最近在项目中遇到需要实现 Apk 多渠道.定制化打包, Google .百度查找了一些资料, ...
- Xamarin+Prism小试牛刀:定制跨平台Outlook邮箱应用(后续)
在[Xamarin+Prism小试牛刀:定制跨平台Outlook邮箱应用]里面提到了Microsoft 身份认证,其实这也是一大块需要注意的地方,特作为后续补充这些知识点.上章是使用了Microsof ...
- Django admin定制化,User字段扩展[原创]
前言 参考上篇博文,我们利用了OneToOneField的方式使用了django自带的user,http://www.cnblogs.com/caseast/p/5909248.html , 但这么用 ...
- 用Kotlin实现Android定制视图(KAD 06)
作者:Antonio Leiva 时间:Dec 27, 2016 原文链接:https://antonioleiva.com/custom-views-android-kotlin/ 在我们阅读有关c ...
- CSharpGL(28)得到高精度可定制字形贴图的极简方法
CSharpGL(28)得到高精度可定制字形贴图的极简方法 回顾 以前我用SharpFont实现了解析TTF文件从而获取字形贴图的功能,并最终实现了用OpenGL渲染文字. 使用SharpFont,美 ...
- 不懂CSS也能定制博客界面!
之前没想过定制博客界面,毕竟CSS,HTML什么的都不懂,不过看了这篇文章分分钟搞定: [详细图解]一步一步教你自定义博客园(cnblog)界面 我是基于模板BlueSky做了些改动,先看修改前后的效 ...
随机推荐
- laravel的启动过程解析
laravel的启动过程,也是laravel的核心,对这个过程有一个了解,有助于得心应手的使用框架,希望能对大家有点帮助. 统一入口 laravel框架使用了统一入口,入口文件:/public/ind ...
- JS模块化编程(一):CommonJS,AMD/CMD
前言 模块化是什么? 为什么采用模块化? 场景: 一个html,因不同的业务需求开发,会不断的引入js文件.另外,a.js和b.js中的变量或函数必须是全局的,才能暴露给使用方. <script ...
- 002_JavaSE笔记:单例模式
一.应用杨景 在计算机系统中,线程池.缓存.日志对象.对话框.打印机.显卡的驱动程序对象常被设计成单例.这些应用都或多或少具有资源管理器的功能.每台计算机可以有若干个打印机,但只能有一个Printer ...
- Java编程的逻辑 (72) - 显式条件
本系列文章经补充和完善,已修订整理成书<Java编程的逻辑>,由机械工业出版社华章分社出版,于2018年1月上市热销,读者好评如潮!各大网店和书店有售,欢迎购买,京东自营链接:http: ...
- Error:Makefile:452: target 'config' given more than once in the same rule
在解压的 linux2.6.15 文件夹下 make menuconfig 的时候出现下面的错误: Makefile:452: target 'config' given more than once ...
- SpringMVC框架06——文件上传与下载
1.文件上传 Spring MVC框架的文件上传是基于commons-fileupload组件的文件上传,只不过Spring MVC框架在原有文件上传组件上做了进一步封装,简化了文件上传的代码实现. ...
- PMP 考试 形式
200 道单选题- 考试时间为4个小时(上午9点到下午1点) 1年4次考试时间 2017年 3月18 6月24 9月9 10月9 考试费用3300 PMBOK
- IP基础知识与分配实现
一.IP寻址 1.划分网络ID和主机ID的最初方案是使用地址分类. 2.A类:0.0.0.0-127.255.255.255 B类:128.0.0.0-191.255.255.255 C类:192.0 ...
- ICE::Handle 使用崩溃问题
简单例子如下: #include "Ice/Ice.h" #include "IceUtil/IceUtil.h" #include "Printer ...
- Message Queue协议AMQP
历史: Message Queue的需求由来已久,80年代最早在金融交易中,高盛等公司采用Teknekron公司的产品,当时的Message queuing软件叫做:the information b ...