完全定制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. prometheus的平台侧和应用侧结合,实现应用的metrics的抓取

    这个细节,迷惑了我一段时间,前面也写过一篇blog,描述过这个问题. 今天看到一种更好的解决方法. 记录一下. prometheus在k8s集群里,抓取应用的metrics. 是需要平台侧和应用侧相互 ...

  2. 《NodeJS开发指南》第五章微博实例开发总结

    所有文章搬运自我的个人主页:sheilasun.me <NodeJS开发指南>这本书用来NodeJS入门真是太好了,而且书的附录部分还讲到了闭包.this等JavaScript常用特性.第 ...

  3. docker重命名镜像

    一.docker tag IMAGEID(镜像id) REPOSITORY:TAG(仓库:标签)

  4. 20172301 《Java软件结构与数据结构》实验二报告

    20172301 <Java软件结构与数据结构>实验二报告 课程:<Java软件结构与数据结构> 班级: 1723 姓名: 郭恺 学号:20172301 实验教师:王志强老师 ...

  5. JSP中的Java代码和内置对象

    一.JSP中的Java代码 (一)JSP页面中有三种方式嵌入java代码: 1.java的表达式 格式:<%= java表达式 %> 2.java的语句 格式:<% java语句&g ...

  6. 如何对vue项目进行优化,加快首页加载速度

    上个月上线了一个vue小项目,刚做完项目,打包上线之后,传到服务器上发现首页加载巨慢. 由于开发时间比较紧,我想着怎么快怎么来,因而在开发过程中没考虑过优化性能问题,酿成最后在带宽5M的情况下页面加载 ...

  7. Codeforces.1027F.Session in BSU(思路 并查集)

    题目链接 \(Description\) 有\(n\)个人都要参加考试,每个人可以在\(ai\)或\(bi\)天考试,同一天不能有两个人考试.求最晚考试的人的时间最早能是多少.无解输出-1. \(So ...

  8. zoj 3659 第37届ACM/ICPC 长春赛区现场赛E题 (并查集)

    题意:给出一棵树,找出一个点,求出所有点到这个点的权值和最大,权值为路径上所有边权的最小值. 用神奇的并查集,把路按照权值从大到小排序,然后用类似Kruskal的方法不断的加入边. 对于要加入的一条路 ...

  9. Spring_之注解事务 @Transactional

    spring 事务注解 默认遇到throw new RuntimeException("...");会回滚需要捕获的throw new Exception("...&qu ...

  10. sagas

    http://mp.weixin.qq.com/s?src=3&timestamp=1503011877&ver=1&signature=cngvQj8-8qYsYcHR-5A ...