完全定制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做了些改动,先看修改前后的效 ...
随机推荐
- MyBatis使用示例
下面是一个简单的MyBatis使用DEMO. 整体结构 整体代码大致如下: POM依赖 需要引用两个jar包,一个是mybatis,另一个是mysql-connector-java,如果是maven工 ...
- 【AtCoder】ARC089
C - Traveling 先看能不能走到,再看看奇偶性是否相同 #include <bits/stdc++.h> #define fi first #define se second # ...
- ZOJ Monthly, March 2018 题解
[题目链接] A. ZOJ 4004 - Easy Number Game 首先肯定是选择值最小的 $2*m$ 进行操作,这些数在操作的时候每次取一个最大的和最小的相乘是最优的. #include & ...
- 【python学习-2】python起步必备
1.python缩进 python 缩进是tab,还是空格呢?都可以,可以是一个tab,也可以是4个空格,但是最重要的是整个python脚本的缩进必须统一,否则会报错. 2.代码注释 python注释 ...
- eclipse launching workspace太慢的解决方法
这几天eclipse调试Android项目的时候反应超慢,右下显示launching workspace就不怎么动了,今天终于卡的受不了了,在网上搜了写方法,设置了下总算好点了,现在把方法贴出来,跟大 ...
- Java异常类层次结构图
1. 分类图镇楼: 2.运行时异常与非运行时异常区别: Java 提供了两类主要的异常 :runtime exception 和 checked exception. 2.1 checked exce ...
- Xamarin iOS教程之编辑界面编写代码
Xamarin iOS教程之编辑界面编写代码 Xamarin iOS的Interface Builder Interface Builder被称为编辑界面.它是一个虚拟的图形化设计工具,用来为iOS应 ...
- centos7 静默安装oracle
系统centos7.4 mini 关闭selinux.firewalld 配置主机名: hostnamectl set-hostname --static oracle 之前说oracle不认cen ...
- 「BZOJ 3645」小朋友与二叉树
「BZOJ 3645」小朋友与二叉树 解题思路 令 \(G(x)\) 为关于可选大小集合的生成函数,即 \[ G(x)=\sum[i\in c ] x^i \] 令 \(F(x)\) 第 \(n\) ...
- 2010-2011 ACM-ICPC, NEERC, Moscow Subregional Contest Problem I. Interest Targeting 模拟题
Problem I. Interest Targeting 题目连接: http://codeforces.com/gym/100714 Description A unique display ad ...