完全定制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做了些改动,先看修改前后的效 ...
随机推荐
- asserts文件存到外部SD卡里
package com.example.wang.testapp3; import android.content.res.AssetManager; import android.graphics. ...
- Channel Allocation HDU1373
染色问题:相邻不能染同一种颜色 最少需要的颜色的数量=最大团点的数量 #include<bits/stdc++.h> using namespace std; #define N 27 i ...
- 004 jquery过滤选择器-----------(基本过滤选择器)
1.介绍 2.常见基本过滤器 3.程序 <!DOCTYPE html> <html> <head> <meta charset="UTF-8&quo ...
- wdatepicker默认时间为当前时间
$(document).ready(function() { alert(today()); document.getElementById("serviceTime").valu ...
- 日志回滚:python(日志分割)
日志回滚:python 什么是日志回滚? 答: 将日志信息输出到一个单一的文件中,随着应用程序的持续使用,该日志文件会越来越庞大,进而影响系统的性能.因此,有必要对日志文件按某种条件进行切分,要切分日 ...
- 卡在 构建 gradle 项目信息
之所以卡死是因为Android Studio在初次构建的时候,会联网进行gradle目录的更新操作.断网之后就不会去主动更新了. 断网. 打开项目. 把 gradle 改成 使用当地. ======= ...
- BZOJ.3052.[WC2013]糖果公园(树上莫队 带修改莫队)
题目链接 BZOJ 当然哪都能交(都比在BZOJ交好),比如UOJ #58 //67376kb 27280ms //树上莫队+带修改莫队 模板题 #include <cmath> #inc ...
- BZOJ4317: Atm的树
Description Atm有一段时间在虐qtree的题目,于是,他满脑子都是tree,tree,tree…… 于是,一天晚上他梦到自己被关在了一个有根树中,每条路径都有边权,一个神秘的声音告诉他, ...
- NOIP2015其余几道题
T1: #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> # ...
- 【转】Asp.net实现URL重写
[概述] URL重写就是首先获得一个进入的URL请求然后把它重新写成网站可以处理的另一个URL的过程.重写URL是非常有用的一个功能,因为它可以让你提高搜索引擎阅读和索引你的网站的能力:而且在你改变了 ...