动画隐藏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#正则表达式合并连续空格为单个空格
第一种方法: 使用 System.Text.RegularExpressions.Regex.Replace()方法 string result = String.Empty; string str ...
- php的isset()和empty()区别
转载:http://www.cnblogs.com/ndxsdhy/archive/2011/04/02/2003193.html 1.isset()函数 一般用来检测变量是否设置 (是否已经赋值) ...
- double类型转换为int类型四舍五入工具类
package com.qiyuan.util; import java.math.BigDecimal; import java.text.DecimalFormat; public class G ...
- EXCEL导出工具类及调用
一.Excel导出工具类代码 package com.qiyuan.util; import java.io.OutputStream; import java.io.UnsupportedEncod ...
- b-树和b+树以及mysql索引
b-树(m阶): 1.根节点至少有2个子节点; 2.中间节点包含k个子节点和k-1个元素,m/2 <= k <= m; 3.每个节点中的元素从小到大排列,节点当中k-1个元素正好是k个孩子 ...
- spring下redis使用资料
参考资料地址: spring集成redis Spring缓存注解@Cacheable.@CacheEvict.@CachePut使用 redis常用命令 redis持久化(RDB与AOF) Redis ...
- C# 接口的隐式与显示实现及适应场景
通俗的来讲,“显示接口实现”就是使用接口名称作为方法名的前缀;而传统的实现方式称之为:“隐式接口实现”.废话不说,例子如下: interface IAnimal { void Dog(); } cla ...
- Winform无边框窗体拖动
调用示例 当然,BUG还是有的,不过基本需求倒也可以
- [javaSE] 网络编程(概述)
网络通信的步骤, 1.找到对方的ip 2.数据发送到对方指定的应用程序上,为了标识这些应用程序,用数字进行标识,这个数字就是端口 3.定义通信规则,这个规则就称为协议 国际组织定义了通用协议 TCP/ ...
- 利用CEF山寨一个翻译器
起因 在某些情况下,有将从某种类型的语言翻译成另一种类型语言的需求.比如在生成实体时,可能需要将中文名称转换成英文.于是利用CEFSharp山寨了一个翻译器.效果图如下: CEF简介 CEF全称为Ch ...