动画隐藏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混用是非常常见的,有时候会 ...
随机推荐
- C# 在同一个项目里启动不同的类文件
比如有两个类文件分别为 Person.cs 和 Enum.cs : using System; using person; namespace HelloWorld { class HelloWorl ...
- H5如何用Canvas画布生成并保存带图片文字的新年快乐的海报
摘要:初略算了算大概有20天没有写博客了,原本是打算1月1号元旦那天写一个年终总结的,博客园里大佬们都在总结过去,迎接将来,看得我热血沸腾,想想自己也工作快2年了,去年都没有去总结一下,今年势必要总结 ...
- 在百度搜索里展现网站LOGO
我们经常在百度搜索一些网站可以看到一个网站在百度上展示的三个部分: 网站的名称 如(趣学车) 网站的描述 一段比较详细的对网站的介绍 网站的logo,一张logo图片 如下图 ------ 接下来我们 ...
- RabbitMQ.NET In Window Service
工作中要求使用RabbitMQ,以Windows Service 模式启动,中间有遇到一些问题,网上大部分博客有误导倾向, 在这里做一个简单的记录,以免后面的人走坑: 1. 自动重新连接,不需要手动处 ...
- c#Image.FromFile图形加载异常处理
public void UpdateImg(string picpath) { //更新至控件中 PnlImageShow.BackgroundImage = LoadImgPath(picpath) ...
- HTML5的audio在手机网页上无法自动加载/播放音乐,能否实现该功能?
在IOS中第一次调用play方法播放音频会被阻止,必须得等用户有交互动作,比如touchstart,click后才能正常调用,在微信中可以通过监听WeixinJSBridgeReady事件来提前播放一 ...
- 十九、curator recipes之PathChildrenCache
简介 curator可以监听路径下子节点的变更操作,如创建节点,删除节点 官方文档:http://curator.apache.org/curator-recipes/path-cache.html ...
- java 将页面指定区域截图并上传到服务器
controller层: /** * 上传获取到的收据图片 * @param request * @param data 获取到的图片 * @return */ @RequestMapping(val ...
- 针对多类型数据库,集群数据库的有序GUID
一.背景 常见的一种数据库设计是使用连续的整数为做主键,当新的数据插入到数据库时,由数据库自动生成.但这种设计不一定适合所有场景. 随着越来越多的使用Nhibernate.EntityFramewor ...
- CSS reset的审视
by zhangxinxu from http://www.zhangxinxu.com本文地址:http://www.zhangxinxu.com/wordpress/?p=758 一.CSS re ...