第六篇、抽屉效果+UITabBarController(主流框架)
依赖于第三方的框架RESideMenu
1.AppDelegate.m中的实现
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch. //在AppDelegate.h中声明属性,初始化tabBarController
self.tabBar = [[UITabBarController alloc] init]; ViewController* vc1 = [[ViewController alloc] init];
vc1.tabBarItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemBookmarks tag:];
UINavigationController* nav1 = [[UINavigationController alloc] initWithRootViewController:vc1]; ViewController1* vc2 = [[ViewController1 alloc] init];
vc2.tabBarItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemContacts tag:];
UINavigationController* nav2 = [[UINavigationController alloc] initWithRootViewController:vc2]; self.tabBar.viewControllers = @[nav1,nav2]; //初始化leftVC
LeftController* left = [[LeftController alloc] init]; //初始化RESideMenu
RESideMenu* menu = [[RESideMenu alloc] initWithContentViewController:self.tabBar leftMenuViewController:left rightMenuViewController:nil];
self.window.rootViewController= menu;
return YES;
}
2.left左侧菜单
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
AppDelegate* GHDelegate = (AppDelegate* )[UIApplication sharedApplication].delegate;
ViewController1_1* vc = [[ViewController1_1 alloc] init]; //通过GHDelegate.tabBar.selectedIndex获得当前tabbaritem对应的nav,进行页面跳转
NSArray *arrControllers = GHDelegate.tabBar.viewControllers; if (GHDelegate.tabBar.selectedIndex==) {
UINavigationController* nav = (UINavigationController* )[arrControllers objectAtIndex:];
//隐藏sideMenuViewController
[self.sideMenuViewController hideMenuViewController];
//隐藏底部
vc.hidesBottomBarWhenPushed = YES;
[nav pushViewController:vc animated:YES];
}else{
UINavigationController* nav = (UINavigationController* )[arrControllers objectAtIndex:];
[self.sideMenuViewController hideMenuViewController];
vc.hidesBottomBarWhenPushed = YES;
[nav pushViewController:vc animated:YES];
} }
3.RESideMenu常见的属性设置
- (void)awakeFromNib
{
self.parallaxEnabled = NO; //视图差效果
self.scaleContentView = YES; //中心视图缩放功能打开
self.contentViewScaleValue = 0.95; //侧滑出现时缩放比
self.scaleMenuView = NO; //侧滑出来的视图是否支持缩放
self.contentViewShadowEnabled = YES; //中心视图阴影效果,打开显得有层次感。
self.contentViewShadowRadius = 4.5; //中心视图阴影效果Radius
self.panGestureEnabled = NO; //关闭拖动支持手势 //使用storyboard初始化中心视图和左视图。
self.contentViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"contentViewController"]; //tabbar controller self.leftMenuViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"leftMenuViewController"];
}
附件:
4.设置基本导航控制器
#import "LHLNavigationViewController.h" @interface LHLNavigationViewController () <UIGestureRecognizerDelegate> @end @implementation LHLNavigationViewController + (void)load
{
UINavigationBar *navBar = [UINavigationBar appearanceWhenContainedIn:self, nil];
// 设置导航条字体
NSMutableDictionary *attr = [NSMutableDictionary dictionary];
attr[NSFontAttributeName] = [UIFont systemFontOfSize:];
[navBar setTitleTextAttributes:attr]; // 设置背景图片
[navBar setBackgroundImage:[UIImage imageNamed:@"navigationbarBackgroundWhite"] forBarMetrics:UIBarMetricsDefault];
} - (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated{ if (self.childViewControllers.count > ) { // 非根控制器
// 自定义UIBarButtonItem的分类方法
UIBarButtonItem *item = [UIBarButtonItem backItemWitnImage:[UIImage imageNamed:@"navigationButtonReturn"] heighlightImage:[UIImage imageNamed:@"navigationButtonReturnClick"] target:self action:@selector(back) title:@"返回"];
viewController.hidesBottomBarWhenPushed = YES;
viewController.navigationItem.leftBarButtonItem = item;
} [super pushViewController:viewController animated:animated]; } - (void)back
{
[self popViewControllerAnimated:YES];
} - (void)viewDidLoad {
[super viewDidLoad];
// 全屏返回手势
UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self.interactivePopGestureRecognizer.delegate action:@selector(handleNavigationTransition:)];
pan.delegate = self;
self.interactivePopGestureRecognizer.enabled = NO;
[self.view addGestureRecognizer:pan]; }
/*
<UIScreenEdgePanGestureRecognizer: 0x7f7f98c97430;
state = Possible; delaysTouchesBegan = YES;
view = <UILayoutContainerView 0x7f7f98f19d00>;
target= <(action=handleNavigationTransition:,
target=<_UINavigationInteractiveTransition 0x7f7f98c96ee0>)>
*/ #pragma mark - UIGestureRecognizerDelegate
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
return self.childViewControllers.count > ;
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} @end
5.设置UITabBarViewController
#import "LHLTabBarController.h"
#import "LHLEssenceViewController.h"
#import "LHLFriendTrendViewController.h"
#import "LHLMeViewController.h"
#import "LHLNewViewController.h"
#import "LHLPublishViewController.h"
#import "LHLTabBar.h"
#import "LHLNavigationViewController.h" @interface LHLTabBarController () @end @implementation LHLTabBarController // load方法只会调用一次
+ (void)load
{
// 设置某个类中的 UITabBarItem 按钮的颜色
UITabBarItem *item = [UITabBarItem appearanceWhenContainedIn:self, nil];
NSMutableDictionary *attrs = [NSMutableDictionary dictionary];
attrs[NSForegroundColorAttributeName] = [UIColor blackColor];
[item setTitleTextAttributes:attrs forState:UIControlStateSelected]; // 设置字体的尺寸:只有正常状态下设置才有效果
NSMutableDictionary *attrsNor = [NSMutableDictionary dictionary];
attrsNor[NSFontAttributeName] = [UIFont systemFontOfSize:];
[item setTitleTextAttributes:attrsNor forState:UIControlStateNormal];
} #pragma mark - 初始化
- (void)viewDidLoad {
[super viewDidLoad]; // 1.创建所有子控制器
[self setUpAllChildControllers]; // 2.2设置tabBar按钮的标题
[self setUpAllTitles]; // 3.使用自定义tabBar
[self setUpTabBar]; } #pragma mark - 自定义方法
- (void)setUpAllChildControllers
{
// 2.1.设置tabBar的子控制器
// 精华
LHLEssenceViewController *essenceVC = [[LHLEssenceViewController alloc] init];
LHLNavigationViewController *nav = [[LHLNavigationViewController alloc] initWithRootViewController:essenceVC];
[self addChildViewController:nav]; // 新帖
LHLNewViewController *newVC = [[LHLNewViewController alloc] init];
LHLNavigationViewController *nav1 = [[LHLNavigationViewController alloc] initWithRootViewController:newVC];
[self addChildViewController:nav1]; // 关注
LHLFriendTrendViewController *trendVC = [[LHLFriendTrendViewController alloc] init];
LHLNavigationViewController *nav3 = [[LHLNavigationViewController alloc] initWithRootViewController:trendVC];
[self addChildViewController:nav3]; // 我
LHLMeViewController *meVC = [[LHLMeViewController alloc] init];
LHLNavigationViewController *nav4 = [[LHLNavigationViewController alloc] initWithRootViewController:meVC];
[self addChildViewController:nav4]; } - (void)setUpAllTitles
{
// 精华
UINavigationController *nav = self.childViewControllers[];
[self setTitleButton:nav title:@"精华" image:@"tabBar_essence_icon" selectImage:@"tabBar_essence_click_icon"]; // 新帖
UINavigationController *nav1 = self.childViewControllers[];
[self setTitleButton:nav1 title:@"新帖" image:@"tabBar_new_icon" selectImage:@"tabBar_new_click_icon"]; // 关注
UINavigationController *nav3 = self.childViewControllers[];
[self setTitleButton:nav3 title:@"关注" image:@"tabBar_friendTrends_icon" selectImage:@"tabBar_friendTrends_click_icon"]; // 我
UINavigationController *nav4 = self.childViewControllers[];
[self setTitleButton:nav4 title:@"我" image:@"tabBar_me_icon" selectImage:@"tabBar_me_click_icon"];
} - (void)setTitleButton:(UINavigationController *)nav title:(NSString *)aTitle image:(NSString *)aImage selectImage:(NSString *)aSelectImage
{
nav.tabBarItem.title = aTitle;
nav.tabBarItem.image = [UIImage imageRenderOriginalWithName:aImage];
nav.tabBarItem.selectedImage = [UIImage imageRenderOriginalWithName:aSelectImage];
} - (void)setUpTabBar
{
LHLTabBar *tabBar = [[LHLTabBar alloc] init];
// 利用KVC对系统的tabBar进行赋值: KVC的原理是通过访问属性进行赋值,不是通过setter方法进行赋值
[self setValue:tabBar forKeyPath:@"tabBar"];
} @end
6.分类文件
UIBarButtonItem
#import "UIBarButtonItem+item.h" @implementation UIBarButtonItem (item)
+ (UIBarButtonItem *)itemWitnImage:(UIImage *)aImage heighlightImage:(UIImage *)aSelectImage target:(id)aTarget action:(SEL)aAction
{
UIButton *btn = [[UIButton alloc] init];
[btn setImage:aImage forState:UIControlStateNormal];
[btn setImage:aSelectImage forState:UIControlStateHighlighted];
[btn sizeToFit];
[btn addTarget:aTarget action:aAction forControlEvents:UIControlEventTouchUpInside];
// 添加的代码
UIView *itemView = [[UIView alloc] initWithFrame:btn.bounds];
[itemView addSubview:btn]; return [[UIBarButtonItem alloc] initWithCustomView:itemView];
} + (UIBarButtonItem *)itemWitnImage:(UIImage *)aImage selectedImage:(UIImage *)aSelectImage target:(id)aTarget action:(SEL)aAction
{
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
[btn setImage:aImage forState:UIControlStateNormal];
[btn setImage:aSelectImage forState:UIControlStateSelected];
[btn sizeToFit];
[btn addTarget:aTarget action:aAction forControlEvents:UIControlEventTouchUpInside];
UIView *containerView = [[UIView alloc] initWithFrame:btn.bounds];
[containerView addSubview:btn];
return [[UIBarButtonItem alloc] initWithCustomView:containerView];
} + (UIBarButtonItem *)backItemWitnImage:(UIImage *)aImage heighlightImage:(UIImage *)aSelectImage target:(id)aTarget action:(SEL)aAction title:(NSString *)aTitle
{
UIButton *btn = [[UIButton alloc] init];
[btn setImage:aImage forState:UIControlStateNormal];
[btn setImage:aSelectImage forState:UIControlStateHighlighted];
[btn setTitle:aTitle forState:UIControlStateNormal];
[btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[btn setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted];
btn.contentEdgeInsets = UIEdgeInsetsMake(, -, , );
[btn sizeToFit];
[btn addTarget:aTarget action:aAction forControlEvents:UIControlEventTouchUpInside];
UIView *containerView = [[UIView alloc] initWithFrame:btn.bounds];
[containerView addSubview:btn];
return [[UIBarButtonItem alloc] initWithCustomView:containerView];
} @end
UIImae
#import "UIImage+image.h" @implementation UIImage (image)
// 在周边加一个边框为1的透明像素
- (UIImage *)imageAntialias
{
CGFloat border = 1.0f;
CGRect rect = CGRectMake(border, border, self.size.width-*border, self.size.height-*border); UIImage *img = nil; UIGraphicsBeginImageContext(CGSizeMake(rect.size.width,rect.size.height));
[self drawInRect:CGRectMake(-, -, self.size.width, self.size.height)];
img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext(); UIGraphicsBeginImageContext(self.size);
[img drawInRect:rect];
UIImage* antiImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext(); return antiImage;
}
// 返回一张没有被渲染的图片
+ (UIImage *)imageRenderOriginalWithName:(NSString *)imageName
{
UIImage *image = [UIImage imageNamed:imageName];
image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
return image;
} @end
7.UITabBar
#import "LHLTabBar.h" @interface LHLTabBar () @property (nonatomic, weak) UIButton *plusButton; @end @implementation LHLTabBar - (UIButton *)plusButton{
if (_plusButton == nil) {
UIButton *plusButton = [UIButton buttonWithType:UIButtonTypeCustom];
[plusButton setBackgroundImage:[UIImage imageNamed:@"tabBar_publish_icon"] forState:UIControlStateNormal];
[plusButton setBackgroundImage:[UIImage imageNamed:@"tabBar_publish_click_icon"] forState:UIControlStateHighlighted];
[plusButton sizeToFit];
[self addSubview:plusButton];
_plusButton = plusButton;
}
return _plusButton;
} - (void)layoutSubviews
{
[super layoutSubviews]; // 布局子控件
NSInteger count = self.items.count + ;
CGFloat btnW = self.lhl_width / count;
CGFloat btnH = self.lhl_height; NSInteger i = ;
for (UIButton *tabBarButton in self.subviews) {
// 取出UITabBarButton
if ([tabBarButton isKindOfClass:NSClassFromString(@"UITabBarButton")]) {
if (i == ) {
i += ;
}
tabBarButton.frame = CGRectMake(btnW * i, , btnW, btnH);
i++;
}
// 隐藏tabBar黑线
NSString *subFrames = NSStringFromCGRect(tabBarButton.frame);
NSString *blackLine = @"{{0, -0.5}, {375, 0.5}}";
if ([subFrames isEqualToString:blackLine]) {
tabBarButton.hidden = YES;
} }
// plusButton
self.plusButton.center = CGPointMake(self.lhl_width * 0.5, self.frame.size.height * 0.5); } @end
第六篇、抽屉效果+UITabBarController(主流框架)的更多相关文章
- 第六篇:web之python框架之django
python框架之django python框架之django 本节内容 web框架 mvc和mtv模式 django流程和命令 django URL django views django te ...
- iOS开发——UI进阶篇(十三)UITabBarController简单使用,qq主流框架
一.UITabBarController简单使用 // 程序加载完毕 - (BOOL)application:(UIApplication *)application didFinishLaunchi ...
- iOS开发——实用技术OC篇&简单抽屉效果的实现
简单抽屉效果的实现 就目前大部分App来说基本上都有关于抽屉效果的实现,比如QQ/微信等.所以,今天我们就来简单的实现一下.当然如果你想你的效果更好或者是封装成一个到哪里都能用的工具类,那就还需要下一 ...
- iOS开发——高级篇——iOS抽屉效果实现原理
实现一个简单的抽屉效果: 核心思想:KVO实现监听mainV的frame值的变化 核心代码: #import "ViewController.h" // @"frame& ...
- 搭建App主流框架_纯代码搭建(OC)
转载自:http://my.oschina.net/hejunbinlan/blog/529778?fromerr=EmSuX7PR 搭建主流框架界面 源码地址在文章末尾 达成效果 效果图 注:本文部 ...
- 10分钟搭建 App 主流框架
搭建主流框架界面 0.达成效果 我们玩iPhone应用的时候,有没发现大部分的应用都是上图差不多的结构,下面的TabBar控制器可以切换子控制器,上面又有Navigation导航条 我们本文主要是搭建 ...
- python三大web框架Django,Flask,Flask,Python几种主流框架,13个Python web框架比较,2018年Python web五大主流框架
Python几种主流框架 从GitHub中整理出的15个最受欢迎的Python开源框架.这些框架包括事件I/O,OLAP,Web开发,高性能网络通信,测试,爬虫等. Django: Python We ...
- 第六篇 ANDROID窗口系统机制之显示机制
第六篇 ANDROID窗口系统机制之显示机制 ANDROID的显示系统是整个框架中最复杂的系统之一,涉及包括窗口管理服务.VIEW视图系统.SurfaceFlinger本地服务.硬件加速等.窗口管理服 ...
- 十分钟搭建App主流框架
搭建主流框架界面 0.达成效果 Snip20150904_5.png 我们玩iPhone应用的时候,有没发现大部分的应用都是上图差不多的结构,下面的TabBar控制器可以切换子控制器,上面又有Navi ...
随机推荐
- oracle 11g 没有scott用户下emp的创建方法
oracle 11g 安装后 没有scott 用户, 创建scott 用户后 使用select * from emp查询 emp表, 结果为 找不到行. 运行脚本 utlsample.sql 首先as ...
- JS可以做什么,它的能力范围 View----------Request/Submit------------------Server
View----------Request/Submit------------------Server javascript--------><script>标签方式(页面,动态插 ...
- Media Queries详细
@media only screen and (max-device-width: 480px) { //页面最大宽度480px } <link rel="stylesheet&quo ...
- C和C++函数互相调用
Call C++ function from C & Call C function from C++ (C和C++函数互相调用) By williamxue on Jun 12, 2007 ...
- C++ 二叉树遍历实现
原文:http://blog.csdn.net/nuaazdh/article/details/7032226 //二叉树遍历 //作者:nuaazdh //时间:2011年12月1日 #includ ...
- Golang学习 - sync 包
------------------------------------------------------------ 临时对象池 Pool 用于存储临时对象,它将使用完毕的对象存入对象池中,在需要 ...
- ubuntu 上使用apt-get安装oracle-jdk
Installing default JRE/JDK sudo apt-get updatesudo apt-get install default-jresudo apt-get install d ...
- WPF 之 布局(三)
六.DockPanel DockPanel定义一个区域,在此区域中,您可以使子元素通过描点的形式排列,这些对象位于 Children 属性中.停靠面板其实就是在WinForm类似于Dock属性的元 素 ...
- 关于c#调用c/c++ dll遇到的问题总结
前段时间公司做了个winform程序,需要调用c 的dll去读取卡号的程序,期间遇到些问题,下面来分享下 一.dll路径问题 相信很多开发者都会遇到这个问题,我总结了下我现在有3总方式去解决这个问题: ...
- socket通信简介
转:http://blog.csdn.net/xiaoweige207/article/details/6211577 “一切皆Socket!” 话虽些许夸张,但是事实也是,现在的网络编程几乎都是用的 ...