自定义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控制器的更多相关文章

  1. 自定义UITabBarController

    用的时候直接拷贝代码即可. 1.在AppDelegate设置跟控制器为:PQTabBarController #import "PQTabBarController.h" @int ...

  2. iOS-自定义 UITabBarController

    先来回顾一下UITabBarController ( 稍微详细的在在http://blog.csdn.net/yang198907/article/details/49807011) 伴随UITabB ...

  3. IOS开发之——自定义导航控制器

    BasicNavigationViewController:UINavigationViwController /* 隐藏导航底部线条 */ -(void)viewDidLoad{    [super ...

  4. iOS彩票项目--第一天,自定义TabBar控制器和自定义TabBar,自定义导航控制器

    一.环境配置,和项目层次搭建 二.自定义TabBar 项目中TabBar中的导航按钮美工给的图片太大,图片中包含了图片和文字.最主要的是TabBar上面的按钮图片尺寸是有规定的,当高度大于44的时候, ...

  5. AJ学IOS 之微博项目实战(2)微博主框架-自定义导航控制器NavigationController

    AJ分享,必须精品 一:添加导航控制器 上一篇博客完成了对底部的TabBar的设置,这一章我们完成自定义导航控制器(NYNavigationController). 为啥要做自定义呢,因为为了更好地封 ...

  6. 自定义UITabBarController标签视图控制器

    首先创建一个类,继承自UItabBarController 然后在.m文件中: 这里我有两个宏定义: #define WIDTH (myView.frame.size.width / 4) //我在写 ...

  7. OC中UITabBarController控制器

    UITabBarController UITabBarController(记为O)常用于管理多个导航控制器,例如有ABC三个导航控制器,可以:addChildViewController(记为A), ...

  8. 自定义视图控制器切换(iOS)

    在iOS开发过程中,通常我们会使用UINavigationController,UITabbarController等苹果提供的视图控制器来切换我们的视图.在iOS5之前,如果要自定义容器视图控制器很 ...

  9. IOS开发之自定义UITabBarController

    UITabBarController是开发中经常会用到的一个视图控制器,但是默认的UITabBarController经常不能够完全满足我们的需求,所以我们经常需要自定义一个UITabBarContr ...

随机推荐

  1. Linux命令-用户、用户组、权限

    参考资料: http://www.linuxidc.com/Linux/2014-07/104445.htm    Linux入门教程:如何手动创建一个Linux用户 http://www.linux ...

  2. tcpdump非常实用的抓包实例

    详细的文档见tcpdump高级过滤技巧 基本语法 ========过滤主机--------- 抓取所有经过 eth1,目的或源地址是 192.168.1.1 的网络数据# tcpdump -i eth ...

  3. Java 集合框架(二)—— ArrayList

    二.数组列表 —— ArrayList 1.构造方法 ArrayList 是 Java 中的动态数组,底层实现就是对象数组,只不过数组的容量会根据情况来改变. 它有个带 int 类型参数的构造方法,根 ...

  4. PTA (Advanced Level) 1021 Deepest Root

    Deepest Root A graph which is connected and acyclic can be considered a tree. The hight of the tree ...

  5. Redis运行流程源码解析--转载

    http://blog.nosqlfan.com/html/4007.html http://www.searchdatabase.com.cn/showcontent_62166.htm 导读:本文 ...

  6. MVC部分视图

    // 以视图名使用当前文件夹下的视图 // 如果没有找到,则搜索 Shared 文件夹 @Html.Partial("ViewName")   @Html.Partial(“视图” ...

  7. 撰写html标签的快捷方式2

    1.写一个含有类的标签. div.demo-inline + tap键 就会生成如下<div class="demo-inline"></div> 2.CS ...

  8. Java代理(三)

    前面说到了java的动态代理,但是动态代理依赖于接口,这次来看看cglib来实现的代理... 假设有如下方法,这回没有说接口哦~ package proxy.cglibProxy; public cl ...

  9. IDEA 中edit configurations加号找不到tomcat server

    前言:在本机 idea 中搭建 springMVC 项目,正准备配置 Tomcat 时,发现没有 tomcat server 选项,而我的 idea 是有这个插件的,所以解决问题的方案应该是另一个地方 ...

  10. CentOS 7 yum安装配置mysql

    首先去官网下载要用的yum源 传送门:http://dev.mysql.com/downloads/repo/yum/ yum源文件:/home/mysql57-community-release-e ...