动画隐藏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的更多相关文章

  1. 和iPhone有关的视图控制器:UIViewController、UITabBarController、UINavigationController及其混合用法

    iPhone中的view视图是应用程序对于数据最直观.最直接的呈现方式,如下是我在学习了iPhone中的视图控制器以及由其衍生的特殊子类的总结,希望对那些初学者有所帮助: UIViewControll ...

  2. IOS开发之UITabBarController与UINavigationController混合使用

    ios开发中UITabBarController与UINavigationController混合使用是很多app的基础页面结构,下面是简单的的页面初始化的方法,在AppDelegate.m的 - ( ...

  3. UITabBarController 和 UINavigationController 的详解

    首先得搞清这两个控制器之间的层级关系,我们直接看官网给的图,如下所示: 从这张图可以看到:最右边的Assembled views是呈现给用户的界面,它左边的Window是最底层的窗口,重点来了,再往左 ...

  4. iOS 自定义Tabbar实现push动画隐藏效果

    http://wonderffee.github.io/blog/2013/08/07/hide-custom-tab-bar-with-animation-when-push/ 在之前的一篇文章(链 ...

  5. 混合使用UITabBarController和UINavigationController

    混合使用这两个控件的好处是我们可以在NavigationBar添加更多的东西,如标题,按钮等.让用户能够获得更多的信息. UITabBarController的属性ViewControllers接受以 ...

  6. swift:用UITabBarController、UINavigationController、模态窗口简单的搭建一个QQ界面

    搭建一个QQ界面其实是一个很简单的实现,需要几种切换视图的控制器组合一起使用,即导航控制器.标签栏控制器.模态窗口.其中,将标签栏控制器设置为window的rootViewController,因为Q ...

  7. UITabBarController 笔记(三) UITabBarController 配合 UINavigationController 的使用

    建个空的iOS工程 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictiona ...

  8. jquery动画(控制动画隐藏、显示时间轴)

    <!DOCTYPE html><html> <head>    <meta http-equiv="Content-type" conte ...

  9. UINavigationController与UITabBarController相关问题

    UINavigationController与UITabBarController相关问题 UINavigationController与UITabBarController混用是非常常见的,有时候会 ...

随机推荐

  1. Centos 安装python3

    安装python3 大多数云平台没有安装zlib和openssl的devel包,需要提前安装   下载python源码 cd /home/cheat wget https://www.python.o ...

  2. Fiddler HTTPS抓包

    现在很多带有比较重要信息的接口都使用了安全性更高的HTTPS,而Fiddler默认是抓取HTTP类型的接口,要想查看HTTPS类型接口就需要安装fiddler证书.   fiddler安装教程可参考: ...

  3. java date相关

    public static void getPreDay() throws ParseException{     String dateStr="2013-1-1";     D ...

  4. s11d27 算法

    s11d27 算法 一.理论 1.1 时间复杂度和空间复杂度的理论: 1)空间复杂度: 是程序运行所以需要的额外消耗存储空间,一般的递归算法就要有o(n)的空间复杂度了, 简单说就是递归集算时通常是反 ...

  5. c#基础学习(0806)之接口学习

    首先了解一下什么是接口: 1.接口就是一种规范,协议,约定好遵守某种规范就可以写通用的代码 2.定义了一组具有各种功能的方法(只是一种能力,没有具体实现,像抽象方法一样,“关说不做”) 接口存在的意义 ...

  6. 结合after使用content

    结合after或before伪类,在元素的开头或结尾附加上一定的内容,content:""的引号中即是添加的内容,比如说我们这么写: <div>学而时习之不亦说乎< ...

  7. Java常见的同步和异步的区别、特点、联系

    Java常见的同步和异步的区别.特点.联系   同步:发送一个请求,等待返回,然后再发送下一个请求 异步:发送一个请求,不等待返回,随时可以再发送下一个请求 同步可以避免出现死锁,读脏数据的发生,一般 ...

  8. Oracle ORA12514 监听程序当前无法识别连接描述符中请求的服务

    在连接数据库的时候,有时会遇到一个“ORA12514:监听程序当前无法识别连接描述符中请求的服务”的错误,这个错误其实就是数据库动态注册(关于动态注册会在稍后讲解)不生效,导致监听器无法识别客户端连接 ...

  9. <!DOCTYPE html>声明下div高度100%

    问题:在HTML页面中声明<!DOCTYPE html>,页面中div属性设置100%页面显示不正常 body { max-width: 720px; margin: 0 auto; } ...

  10. Implementation:Binary Indexed Tree 树状数组

    #include <iostream> #include <cstdlib> using namespace std; class BinaryIndexedTree { pr ...