自定义UITabbarController控制器
自定义UITabbarController控制器

这是定制UITabbarController的基本原理,没有进行功能性封装.
效果:

源码地址:
https://github.com/YouXianMing/Custom-TabbarController-Verson-One/tree/master
https://github.com/YouXianMing/Custom-TabbarController-Verson-Two/tree/master
源码:
//
// ViewController.m
// TabbarController
//
// Created by XianMingYou on 15/4/15.
// Copyright (c) 2015年 XianMingYou. All rights reserved.
// #import "ViewController.h" #import "FirstViewController.h"
#import "SecondViewController.h" #import "UIButton+DemoUse.h" typedef enum : NSUInteger {
FIRST = 0x12,
SECOND,
BACK_VIEW,
} EButtonFlag; @interface ViewController () @property (nonatomic, strong) FirstViewController *first;
@property (nonatomic, strong) SecondViewController *second; @property (nonatomic, strong) UIViewController *current; @end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad]; self.view.backgroundColor = [UIColor whiteColor]; // 初始化第一个控制器
self.first = [FirstViewController new];
[self addChildViewController:self.first]; // 初始化第二个控制器
self.second = [SecondViewController new];
[self addChildViewController:self.second]; // 加载第一个控制器的视图
[self.first didMoveToParentViewController:self];
[self.view addSubview:self.first.view]; // 简易存储当前控制器
self.current = self.first; // 创建出按钮
[self createButtons];
} - (void)createButtons {
UIView *backView = [[UIView alloc] initWithFrame:CGRectMake(, , , )];
backView.tag = BACK_VIEW;
[self.view addSubview:backView]; // 控制器1按钮
[UIButton createButtonWithFrame:CGRectMake(, , , )
withTag:FIRST
withTitle:@"First"
withFont:nil
addTarget:self
action:@selector(buttonEvent:)
haveBorder:YES
insertInView:backView]; // 控制器2按钮
[UIButton createButtonWithFrame:CGRectMake( + , , , )
withTag:SECOND
withTitle:@"Second"
withFont:nil
addTarget:self
action:@selector(buttonEvent:)
haveBorder:YES
insertInView:backView];
} - (void)buttonEvent:(UIButton *)button { if (button.tag == FIRST) { // 此句话必加(否则点击两次的话会报错)
if ([self.current isEqual:self.first]) {
return;
} // 控制器转场
[self transitionFromViewController:self.current
toViewController:self.first
duration:
options:UIViewAnimationOptionTransitionNone
animations:^{
} completion:^(BOOL finished) {
self.current = self.first; // 将按钮设置到最前面
[self.view bringSubviewToFront:[self.view viewWithTag:BACK_VIEW]];
}]; } else if (button.tag == SECOND) { // 此句话必加(否则点击两次的话会报错)
if ([self.current isEqual:self.second]) {
return;
} // 控制器转场
[self transitionFromViewController:self.current
toViewController:self.second
duration:
options:UIViewAnimationOptionTransitionNone
animations:^{
} completion:^(BOOL finished) {
self.current = self.second; // 将按钮设置到最前面
[self.view bringSubviewToFront:[self.view viewWithTag:BACK_VIEW]];
}]; } } @end


自定义UITabbarController控制器的更多相关文章
- 自定义UITabBarController
用的时候直接拷贝代码即可. 1.在AppDelegate设置跟控制器为:PQTabBarController #import "PQTabBarController.h" @int ...
- iOS-自定义 UITabBarController
先来回顾一下UITabBarController ( 稍微详细的在在http://blog.csdn.net/yang198907/article/details/49807011) 伴随UITabB ...
- IOS开发之——自定义导航控制器
BasicNavigationViewController:UINavigationViwController /* 隐藏导航底部线条 */ -(void)viewDidLoad{ [super ...
- iOS彩票项目--第一天,自定义TabBar控制器和自定义TabBar,自定义导航控制器
一.环境配置,和项目层次搭建 二.自定义TabBar 项目中TabBar中的导航按钮美工给的图片太大,图片中包含了图片和文字.最主要的是TabBar上面的按钮图片尺寸是有规定的,当高度大于44的时候, ...
- AJ学IOS 之微博项目实战(2)微博主框架-自定义导航控制器NavigationController
AJ分享,必须精品 一:添加导航控制器 上一篇博客完成了对底部的TabBar的设置,这一章我们完成自定义导航控制器(NYNavigationController). 为啥要做自定义呢,因为为了更好地封 ...
- 自定义UITabBarController标签视图控制器
首先创建一个类,继承自UItabBarController 然后在.m文件中: 这里我有两个宏定义: #define WIDTH (myView.frame.size.width / 4) //我在写 ...
- OC中UITabBarController控制器
UITabBarController UITabBarController(记为O)常用于管理多个导航控制器,例如有ABC三个导航控制器,可以:addChildViewController(记为A), ...
- 自定义视图控制器切换(iOS)
在iOS开发过程中,通常我们会使用UINavigationController,UITabbarController等苹果提供的视图控制器来切换我们的视图.在iOS5之前,如果要自定义容器视图控制器很 ...
- IOS开发之自定义UITabBarController
UITabBarController是开发中经常会用到的一个视图控制器,但是默认的UITabBarController经常不能够完全满足我们的需求,所以我们经常需要自定义一个UITabBarContr ...
随机推荐
- celery在Django中的应用
这里不解释celery,如果不清楚可以参考下面链接: http://docs.celeryproject.org/en/latest/getting-started/introduction.html ...
- Redis笔记(五):Redis发布订阅
Redis 发布订阅 Redis 发布订阅(pub/sub)是一种消息通信模式:发送者(pub)发送消息,订阅者(sub)接收消息. Redis 客户端可以订阅任意数量的频道. 下图展示了频道 cha ...
- 使用gitlab, jenkins搭建CI(持续集成)系统(2) -- 配置webhook触发构建
1. 在gitlab上配置192.168.1.30的ssh秘钥,使jenkins可以操作gitlab上的project 进入gitlab,点击右上角 点击 Settings -> SSH key ...
- Sass进阶之路,之一(基础篇)
Sass 学习Sass之前,应该要知道css预处理器这个东西,css预处理器是什么呢? Css预处理器定义了一种新的语言将Css作为目标生成文件,然后开发者就只要使用这种语言进行编码工作了.预处理器通 ...
- Linux系统资源管理 之 硬件信息
1. CPU lscpu : 一般不加参数,直接使用该命令. cat /proc/cpuinfo: 该文件中列出了CPU的详细信息,类似于'lscpu'命令 lscpu [niesh @niesh D ...
- 详解REST架构风格
编辑推荐: 本文来自于segmentfault.com,一起了解REST的内在,认识REST的优势,而不再将它当作是“理所当然” 引言 作为Web开发者,你可能或多或少了解一些REST的知识,甚至已经 ...
- mvc手把手教你写excel导入
实习狗的每天新知识日常 准备工作: 1.在项目中添加对NPOI的引用,NPOI下载地址:http://npoi.codeplex.com/releases/view/38113 2.NPOI学习系列教 ...
- 解决升级Nodepad++都会让插件失效
主要原因是Plugin Manager失效导致的,需要重新导入 导入一下PluginManager就可以了地址:https://github.com/bruderstein/nppPluginMana ...
- Apache Spark Exception in thread “main” java.lang.NoClassDefFoundError: scala/collection/GenTraversableOnce$class
问题: 今天用Maven搭建了一个Spark的Scala项目,运行后遇到下面异常: Apache Spark Exception in thread “main” java.lang.NoClassD ...
- 【转】SQL语句统计每天、每月、每年的数据
原文:https://www.cnblogs.com/Fooo/p/3435687.html SQL语句统计每天.每月.每年的数据 1.每年select year(ordertime) 年,sum(T ...