TabBarViewController的创建以及渐变隐藏
// CustomTabBarViewController.h #import <UIKit/UIKit.h>
@interface CustomTabBarViewController : UITabBarController + (void)deallocTabbar;
+ (id)defaultsTabBar; - (void)selectBUttonWithIndex:(NSInteger)index;
-(void)setTabBarHidden:(BOOL)Bool;
@end
//
// CustomTabBarViewController.m
#import "CustomTabBarViewController.h"
#import "DJSHomeViewController.h"
#import "DJSStudioViewController.h"
#import "DJSAppointmentViewController.h"
#import "DJSMineViewController.h"
#import "Header.h"
#define btnBaseTag 100 static CustomTabBarViewController *defaults;
@interface CustomTabBarViewController ()
{
BOOL tabBarIsShow;
}
@property (nonatomic, strong) UIImageView *baceGroundImage;
@property (nonatomic, strong) NSMutableArray *btnArray; @end @implementation CustomTabBarViewController
@synthesize baceGroundImage, btnArray;
+ (void)deallocTabbar
{
defaults = nil;
}
+ (id)defaultsTabBar
{
if (defaults == nil) {
defaults = [[CustomTabBarViewController alloc] init];
}
return defaults;
} - (void)viewDidLoad {
[super viewDidLoad]; tabBarIsShow = YES;
self.view.backgroundColor = [UIColor colorWithRed:/255.0 green:/255.0 blue:/255.0 alpha:];
self.tabBar.hidden = YES;
DJSHomeViewController *home = [[DJSHomeViewController alloc]init];
UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:home];
DJSStudioViewController *produce = [[DJSStudioViewController alloc]init];
UINavigationController *nav1 = [[UINavigationController alloc] initWithRootViewController:produce]; DJSAppointmentViewController *appoint = [[DJSAppointmentViewController alloc]init];
UINavigationController *nav2 = [[UINavigationController alloc] initWithRootViewController:appoint]; DJSMineViewController *mine = [[DJSMineViewController alloc]init];
UINavigationController *nav3 = [[UINavigationController alloc] initWithRootViewController:mine]; self.viewControllers = @[nav, nav1, nav2, nav3]; btnArray = [[NSMutableArray alloc] init];
[self setCustomTabbarItem];
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
}
- (void)setCustomTabbarItem
{
[btnArray removeAllObjects];
baceGroundImage = [[UIImageView alloc] initWithFrame:CGRectMake(, Main_height-, Main_Width, )];
baceGroundImage.backgroundColor = [UIColor whiteColor]; baceGroundImage.image = [UIImage imageNamed:@"wireframe_bottom@2x"];
baceGroundImage.userInteractionEnabled = YES;
[self.view addSubview:baceGroundImage]; // UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, Main_Width, 0.5)];
// lineView.backgroundColor = [UIColor cyanColor];
// [baceGroundImage addSubview:lineView];
NSArray *imageNameArr = @[@"home_unicorn_unpress", @"home_project_unpress", @"home_studio_unpress",@"home_my_unpress"];
NSArray *selecNameArr = @[@"home_unicorn_press", @"home_project_press", @"home_studio_press",@"home_my_press"];
CGFloat space = Main_Width/;
for (NSInteger i = ; i < ; i++) {
UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(i * space, , space, )];
// btn.backgroundColor = [UIColor cyanColor];
[btn setImage:[UIImage imageNamed:imageNameArr[i]] forState:UIControlStateNormal];
[btn setImage:[UIImage imageNamed:selecNameArr[i]] forState:UIControlStateSelected];
btn.tag = btnBaseTag + i;
if (i == )
{
btn.selected = YES;
}
[btn addTarget:self action:@selector(pressBtn:) forControlEvents:UIControlEventTouchUpInside];
[baceGroundImage addSubview:btn];
[btnArray addObject:btn];
}
}
- (void)selectBUttonWithIndex:(NSInteger)index
{
UIButton *btn = (UIButton *)btnArray[index];
[self pressBtn:btn];
} -(void)setTabBarHidden:(BOOL)Bool
{ if (Bool) {
[self hideTabBar];
}
else{
[self showTabBar];
}
} - (void)hideTabBar {
if (!tabBarIsShow)
{ //already hidden
return;
}
[UIView animateWithDuration:0.35 animations:^{
baceGroundImage.frame = CGRectMake(, Main_height, Main_Width, );
}];
tabBarIsShow = NO;
} - (void)showTabBar {
if (tabBarIsShow)
{ // already showing
return;
}
[UIView animateWithDuration:0.35 animations:^{
baceGroundImage.frame = CGRectMake(, Main_height-, Main_Width, );
}]; tabBarIsShow = YES;
} -(void)pressBtn:(id)sender
{
UIButton *btn=(UIButton *)sender; if (btn.tag - btnBaseTag >= self.viewControllers.count) {
return;
}
self.selectedIndex = btn.tag - btnBaseTag;
for (UIButton *tempBtn in btnArray)
{
if (tempBtn.tag == btn.tag)
{
tempBtn.selected=YES;
}
else
{
tempBtn.selected=NO;
}
}
}
@end
1、创建
@interface AppDelegate ()
{
CustomTabBarViewController *tabbar;
}
tabbar=[CustomTabBarViewController defaultsTabBar];
self.window.rootViewController = tabbar;
2、隐藏
CustomTabBarViewController * tabBar =[CustomTabBarViewController defaultsTabBar];
[tabBar setTabBarHidden:YES];


TabBarViewController的创建以及渐变隐藏的更多相关文章
- CSS字体渐变 & 隐藏浏览器滚动条 & grid布局(转载)
字体渐变 https://www.zhangxinxu.com/study/201104/css3-text-gradient-2.html 隐藏浏览器滚动条 https://blog.csdn. ...
- canvas 创建颜色渐变柱状图
最终结果: 代码: <!DOCTYPE html> <html> <head lang="en"> <meta charset=" ...
- css实现内容渐变隐藏效果,手机网页版知乎内容隐藏效果的实现
看到一个需求,如下图,知乎手机网页版的一个视觉效果,对内容很长的部分有一个渐变的隐藏的效果,个人觉得这个设计还是很好的,符合手机大小的应用场景,没有一下子显示完全,可以很快的滑倒页面底部,一定程度上减 ...
- Vuforia图像追踪,动态创建的对象隐藏显示的坑
刚做的一个项目,使用Unity3D的Vuforia插件进行图像识别,其中有动态生成的游戏对象模型,地形模型放在ImageTarget下,作为ImageTarget的子物体. 动态生成的敌人则有Pref ...
- iOS开发之创建颜色渐变视图View
在iOS开发中有时需要自己自定义一个视图view的背景,而网上有人提出的在循环中不断alloc的方法设置其背景色渐变,会耗费很多内存和资源,极其不明智,而在CALayer中早就提供有图层渐变的类和相应 ...
- svg和css3创建环形渐变进度条
在负责的项目中,有一个环形渐变读取进度的效果的需求,于是在网上查阅相关资料整理一下.代码如下: <!DOCTYPE html> <html lang="en"&g ...
- Ionic2 渐变隐藏导航栏|标题栏
废话少说 直接上代码.... //导入需要用到的命名空间 ViewChild,Content import { Component, ViewChild } from '@angular/core'; ...
- IOS 创建渐变图层
代码如下 typedef enum { GradientLayerKindLeftRight = , GradientLayerKindUpDown, GradientLayerKindLBRT,// ...
- canvas 创建渐变图形
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...
随机推荐
- CSS选择器以及优先级与匹配原理
最常用的五类CSS选择器 准确而简洁的运用CSS选择器会达到非常好的效果.我们不必通篇给每一个元素定义类(class)或ID,通过合适的组织,可以用最简单的方法实现同样的效果.在实际工作中,最常用的选 ...
- EF架构~为EF DbContext生成的实体添加注释(T5模板应用)(转载)
转载地址:http://www.newlifex.com/showtopic-1072.aspx 最近新项目要用Entity Framework 6.x,但是我发现从数据库生成模型时没有生成字段的注释 ...
- linq lambda GroupBy 用法
Linq 中按照多个值进行分组(GroupBy) /// <summary>要查询的对象</summary> class Employee { public int ID ...
- wp8 入门到精通 LINQ to SQL
http://msdn.microsoft.com/zh-cn/library/bb397924.aspx LINQ 查询操作中的类型关系 (C#) 使用一个人类发明快速检索的方法 // Northw ...
- java web开发问题集合
前台和后台的交流到底是借助什么?servlet?xml? 我们能感觉到用servlet,但是我们是如何使用servlet的?不是现在web.xml部署后,才能触发吗?所以其实我们是本质是借助XML文件 ...
- 十六进制数'\0x'和'\x'有什么区别?(转)
区别不大,都是把数按16进制输出. \0x:当输出的数转换为16进制只有1位时,在前面补0,如 0a,其它情况按照实际情况输出. \x:按照输出数转换为16进制的实际位数输出. 此外,小写x和大写X也 ...
- HDU 1796 How many integers can you find 容斥入门
How many integers can you find Problem Description Now you get a number N, and a M-integers set, y ...
- Fibonacci Again
Problem Description There are another kind of Fibonacci numbers: F(0) = 7, F(1) = 11, F(n) = F(n-1) ...
- OI再见
以下是一只蒟蒻的回忆: 1.进入高一 小县城不重视OI,直到进了高中才知道有OI这个东西,于是我就开始了OI…(看,够弱的吧,相信你是小学就开始学了) 学了几天Pascal语法后,被老师报上了NOIP ...
- 数据库操作sql【转】
Student(S#,Sname,Sage,Ssex) 学生表Course(C#,Cname,T#) 课程表SC(S#,C#,score) 成绩表Teacher(T#,Tname) 教师表 问题:1. ...