动画隐藏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. WPF中List的Add()与Insert()方法的区别

    先来看看定义: // Summary: // Adds an object to the end of the System.Collections.Generic.List<T>. // ...

  2. 五个步骤教你理清Redis与Memcached的区别

    欢迎大家前往腾讯云+社区,获取更多腾讯海量技术实践干货哦~ 本文由Super发表于云+社区专栏 memcached和redis,作为近些年最常用的缓存服务器,相信大家对它们再熟悉不过了.前两年还在学校 ...

  3. linux svn 开机启动

    在/etc/init.d中建立svnboot,内容如下: #!/bin/bash if [ ! -f "/usr/bin/svnserve" ] then echo "s ...

  4. 安装sublime text2 for ubuntu

        Add our Sublime Text 2 Ubuntu PPA using the following commands: sudo add-apt-repository ppa:webu ...

  5. RabbitMQ 上手记录-part 1-基础概念

    RabbitMQ是什么,不用多介绍了,毕竟名声在那,江湖地位摆着,搜索引擎收录着.为什么突然去学习这个框架了,毕竟工作中没有用得上(说来也惭愧,工作中开发的项目没有使用这个框架).但是作为互联网分布式 ...

  6. BG.Hive - part1

    1. Hive架构 What is hive? Facebook,https://en.wikipedia.org/wiki/Apache_Hive a> 一种工具,可以通过SQL轻松的访问数据 ...

  7. Deep Q-Network 学习笔记(六)—— 改进④:dueling dqn

    这篇同样是完全没看懂 Orz,这里只做实现记录.. 要改动的地方只是在神经网络的最后一层做下调整即可. def create(self): neuro_layer_1 = 3 w_init = tf. ...

  8. [javaSE] 基本类型(String相关)

    字符串是一个特殊的对象 字符串一旦初始化就不可以被改变 获取字符串的长度 调用String对象的length()方法,返回int长度 获取某个索引位置的字符 调用String对象的charAt()方法 ...

  9. 【原】Nginx搭建FTP服务器的细节问题

    关于文件服务器很多实现方法,比如采用阿里的分布式文件系统FastDFS,以及自己内部搭建FTP服务器,这里记录一下关于nginx搭建FTP文件系统流程. ftp服务器搭建的步骤网上也是很多,这里贴一下 ...

  10. mysql数据库定时任务

    应用系统运行中,经常需要定时执行一些任务,例如:定时更新汇总数据,定时更新状态数据等,目前 Treesoft数据库管理系统 增加[定时任务]功能,直接通过页面简单配置,即可按调度规则定时执行SQL任务 ...