动画隐藏UITabBarController与UINavigationController
动画隐藏UITabBarController与UINavigationController
效果图:
源码:
AppDelegate.m
//
// AppDelegate.m
// HideTabbar
//
// Copyright (c) 2014年 Y.X. All rights reserved.
// #import "AppDelegate.h"
#import "RootViewController.h" @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
UITabBarController *tab = [[UITabBarController alloc] init];
tab.viewControllers = @[[RootViewController new]];
UITabBar *tabBar = tab.tabBar;
UITabBarItem *tabBarItem = [tabBar.items objectAtIndex:];
tabBarItem.title = @"YouXianMing";
NSDictionary *textDic = \
@{NSFontAttributeName: [UIFont fontWithName:@"HelveticaNeue-Thin"
size:.f]};
[tabBarItem setTitlePositionAdjustment:UIOffsetMake(, -.f)];
[tabBarItem setTitleTextAttributes:textDic
forState:UIControlStateNormal]; UINavigationController *NC = \
[[UINavigationController alloc] initWithRootViewController:tab];
self.window.rootViewController = NC;
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
} @end
RootViewController.m
//
// RootViewController.m
// HideTabbar
//
// Copyright (c) 2014年 Y.X. All rights reserved.
// #import "RootViewController.h" @interface RootViewController () @property (nonatomic, assign) BOOL flag; @end @implementation RootViewController - (void)viewDidLoad
{
[super viewDidLoad];
self.view.layer.contents = (__bridge id)([UIImage imageNamed:@"back"].CGImage); // 添加手势
UITapGestureRecognizer *tap = \
[[UITapGestureRecognizer alloc] initWithTarget:self
action:@selector(event:)];
[self.view addGestureRecognizer:tap];
} - (void)event:(UITapGestureRecognizer *)tap
{
if (!_flag)
{
[self hideTabBar:self.tabBarController];
}
else
{
[self showTabBar:self.tabBarController];
} _flag = !_flag;
} - (void)hideTabBar:(UITabBarController *)tabbarcontroller
{
// 隐藏导航栏
[self.navigationController setNavigationBarHidden:YES animated:YES]; // 隐藏tabbar
[UIView animateWithDuration:UINavigationControllerHideShowBarDuration animations:^{
for(UIView *view in tabbarcontroller.view.subviews)
{
if([view isKindOfClass:[UITabBar class]])
{
[view setFrame:CGRectMake(view.frame.origin.x,
view.frame.origin.y + ,
view.frame.size.width,
view.frame.size.height)];
}
else
{
[view setFrame:CGRectMake(view.frame.origin.x,
view.frame.origin.y,
view.frame.size.width,
view.frame.size.height + )];
}
}
}];
} - (void)showTabBar:(UITabBarController *)tabbarcontroller
{
// 显示导航栏
[self.navigationController setNavigationBarHidden:NO animated:YES]; // 显示tabbar
[UIView animateWithDuration:UINavigationControllerHideShowBarDuration animations:^{
for(UIView *view in tabbarcontroller.view.subviews)
{
if([view isKindOfClass:[UITabBar class]])
{
[view setFrame:CGRectMake(view.frame.origin.x,
view.frame.origin.y - ,
view.frame.size.width,
view.frame.size.height)];
}
else
{
[view setFrame:CGRectMake(view.frame.origin.x,
view.frame.origin.y,
view.frame.size.width,
view.frame.size.height - )];
}
}
}];
} @end
核心的地方:
动画隐藏UITabBarController与UINavigationController的更多相关文章
- 和iPhone有关的视图控制器:UIViewController、UITabBarController、UINavigationController及其混合用法
iPhone中的view视图是应用程序对于数据最直观.最直接的呈现方式,如下是我在学习了iPhone中的视图控制器以及由其衍生的特殊子类的总结,希望对那些初学者有所帮助: UIViewControll ...
- IOS开发之UITabBarController与UINavigationController混合使用
ios开发中UITabBarController与UINavigationController混合使用是很多app的基础页面结构,下面是简单的的页面初始化的方法,在AppDelegate.m的 - ( ...
- UITabBarController 和 UINavigationController 的详解
首先得搞清这两个控制器之间的层级关系,我们直接看官网给的图,如下所示: 从这张图可以看到:最右边的Assembled views是呈现给用户的界面,它左边的Window是最底层的窗口,重点来了,再往左 ...
- iOS 自定义Tabbar实现push动画隐藏效果
http://wonderffee.github.io/blog/2013/08/07/hide-custom-tab-bar-with-animation-when-push/ 在之前的一篇文章(链 ...
- 混合使用UITabBarController和UINavigationController
混合使用这两个控件的好处是我们可以在NavigationBar添加更多的东西,如标题,按钮等.让用户能够获得更多的信息. UITabBarController的属性ViewControllers接受以 ...
- swift:用UITabBarController、UINavigationController、模态窗口简单的搭建一个QQ界面
搭建一个QQ界面其实是一个很简单的实现,需要几种切换视图的控制器组合一起使用,即导航控制器.标签栏控制器.模态窗口.其中,将标签栏控制器设置为window的rootViewController,因为Q ...
- UITabBarController 笔记(三) UITabBarController 配合 UINavigationController 的使用
建个空的iOS工程 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictiona ...
- jquery动画(控制动画隐藏、显示时间轴)
<!DOCTYPE html><html> <head> <meta http-equiv="Content-type" conte ...
- UINavigationController与UITabBarController相关问题
UINavigationController与UITabBarController相关问题 UINavigationController与UITabBarController混用是非常常见的,有时候会 ...
随机推荐
- 基于TrueLicense实现产品License验证功能
受朋友所托,需要给产品加上License验证功能,进行试用期授权,在试用期过后,产品不再可用. 通过研究调查,可以利用Truelicense开源框架实现,下面分享一下如何利用Truelicense实现 ...
- GRU
GRU模型(比LSTM减少了计算量) LSTM的模型,LSTM的重复网络模块的结构很复杂,它实现了三个门计算,即遗忘门.输入门和输出门. 而GRU模型如下,它只有两个门了,分别为更新门和重置门,即图中 ...
- C#的Equals不区分大小写
代码:System.Windows.Forms.MessageBox.Show("abc".Equals("ABC", StringComparison.Inv ...
- Tornado异步IO
Tornado提供了强大的异步IO机制,提高了服务器的响应能力. @tornado.web.asynchronous tornado默认在处理函数返回时关闭链接,@tornado.web.asynch ...
- DotNetBar 使用笔记
1.删除表格的某一行数据,必须是VirtualMode = false 的时候才生效,不然就只是灰色 SuperDBG_Right.PrimaryGrid.SetDeletedRows(SuperD ...
- fastjson之JSONObject、JSONArray
JSONObject,JSONArray是JSON的两个子类. 首先我们来看JSONObject源码: 会发现JSONObject是继承Map<String, Object>,并且都是使用 ...
- Python__组合数据类型
组合数据:集合类型.序列类型(元组类型.列表类型).字典类型 集合: 定义:集合是多个元素的无序组合.(无序,唯一,Python中要求放入集合中的数据类型是不可变的). 集合用大括号 {}表示,元素间 ...
- CALayer及其子类
前言:这个系列要更新Core Animation的内容,但是CALayer是Core Animation的基础. 一 CALayer是什么? 摘自官网的一句话-Layers Provide the B ...
- NSDictionary 和NSArray 排序(sort)
排序: NSMutableDictionary *dic=[[NSMutableDictionary alloc]init]; [dic setValue:@"第3个" forKe ...
- php5.6+apache2.4+linux搭建php环境
前言 最近突然想搭建个人博客,尽管笔者擅长java-web,但综合各种原因,于是选择了大众化的php+mysql搭建个人博客.对于php,只闻其大名,但从未学过,于是,笔者将从php环境搭建开始,到服 ...