自定义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 ...
随机推荐
- springweb flux 服务器推送事件
以前做服务器推送一般用轮询,后端主动给客户端推送不是很好解决.有时候也可以采用websocket 现在看了springwebflux,用它自带的方法做服务器推送方便多了. 代码如下: import o ...
- C#合并两个Dictionary的方法
直接代码: public Dictionary<string, string> MergeDictionary(Dictionary<string, string> first ...
- word黑底白字
我们在使用word文档编辑文件时,有时候希望某段文字采用黑底白字,以区分其他段落的白底黑字从而达到强调的效果. 方法是: 1. 选中待处理的段落. 2. 点击“设计”选项卡. 3. 找到“设计”选下卡 ...
- solidity如何拼接字符串?
当你开始学习使用solidity开发以太坊智能合约之后,很快你会碰到一个问题: 一.在solidity中该如何拼接字符串? 可能你已经试过了,下面的代码试图把两个字符串使用相加的运算符连接起来,但是这 ...
- [笔记] Python 中JSON数据的读写
前言 JSON(JavaScript Object Notation,JavaScript对象表示法)是一种轻量级的数据交换语言 JSON是独立于语言的文本格式, JSON 数据格式与语言无关 JSO ...
- The "tsconfig.json" file must have compilerOptions.sourceMap set to true
在编译ionic项目的时候出现:Error:The "tsconfig.json" file must have compilerOptions.sourceMap set to ...
- 消息队列系列(二):.Rabbitmq的使用及Web监控工具使用
一.文档资料 1.官方网站:http://www.rabbitmq.com/ 2.安装教程:http://www.rabbitmq.com/install-windows. ...
- 小白学习之Code First(四)
code first :约定大于配置(通过配置实体重写约定) 通过两种方式配置实体:DataAnnotations Fluent Api System.ComponentModel.Data ...
- JavaWeb项目WebContent下的资源文件无法引用
JavaWeb项目引用资源的时候尽量使用绝对路径. 作者在帮助同学完善其JavaWeb项目端页面的时候,css样式文件怎么也引用不了. 第一个想到的是:是不是文件路径写错了? 于是,作者换了绝对路径, ...
- 中小型研发团队架构实践八:分布式协调服务ZooKeeper
一.ZooKeeper 是什么 Apache ZooKeeper 由 Apache Hadoop 的子项目发展而来,于 2010 年 11 月正式成为了 Apache 的顶级项目. ZooKeeper ...