依赖于第三方的框架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(主流框架)的更多相关文章

  1. 第六篇:web之python框架之django

    python框架之django   python框架之django 本节内容 web框架 mvc和mtv模式 django流程和命令 django URL django views django te ...

  2. iOS开发——UI进阶篇(十三)UITabBarController简单使用,qq主流框架

    一.UITabBarController简单使用 // 程序加载完毕 - (BOOL)application:(UIApplication *)application didFinishLaunchi ...

  3. iOS开发——实用技术OC篇&简单抽屉效果的实现

    简单抽屉效果的实现 就目前大部分App来说基本上都有关于抽屉效果的实现,比如QQ/微信等.所以,今天我们就来简单的实现一下.当然如果你想你的效果更好或者是封装成一个到哪里都能用的工具类,那就还需要下一 ...

  4. iOS开发——高级篇——iOS抽屉效果实现原理

    实现一个简单的抽屉效果: 核心思想:KVO实现监听mainV的frame值的变化 核心代码: #import "ViewController.h" // @"frame& ...

  5. 搭建App主流框架_纯代码搭建(OC)

    转载自:http://my.oschina.net/hejunbinlan/blog/529778?fromerr=EmSuX7PR 搭建主流框架界面 源码地址在文章末尾 达成效果 效果图 注:本文部 ...

  6. 10分钟搭建 App 主流框架

    搭建主流框架界面 0.达成效果 我们玩iPhone应用的时候,有没发现大部分的应用都是上图差不多的结构,下面的TabBar控制器可以切换子控制器,上面又有Navigation导航条 我们本文主要是搭建 ...

  7. python三大web框架Django,Flask,Flask,Python几种主流框架,13个Python web框架比较,2018年Python web五大主流框架

    Python几种主流框架 从GitHub中整理出的15个最受欢迎的Python开源框架.这些框架包括事件I/O,OLAP,Web开发,高性能网络通信,测试,爬虫等. Django: Python We ...

  8. 第六篇 ANDROID窗口系统机制之显示机制

    第六篇 ANDROID窗口系统机制之显示机制 ANDROID的显示系统是整个框架中最复杂的系统之一,涉及包括窗口管理服务.VIEW视图系统.SurfaceFlinger本地服务.硬件加速等.窗口管理服 ...

  9. 十分钟搭建App主流框架

    搭建主流框架界面 0.达成效果 Snip20150904_5.png 我们玩iPhone应用的时候,有没发现大部分的应用都是上图差不多的结构,下面的TabBar控制器可以切换子控制器,上面又有Navi ...

随机推荐

  1. 免费LInux主机资源

    一.m-net.arbornet.org注冊 (1)telnet m-net.arbornet.org vista系统默认是关闭telnet的(由于不安全),须要开启.cmd->telnet(2 ...

  2. 【Hybrid App】Hybrid App开发实战

    [引言]近年来随着移动设备类型的变多,操作系统的变多,用户需求的增加,对于每个项目启动前,大家都会考虑到的成本,团队成员, 技术成熟度,时间,项目需求等一堆的因素.因此,开发App的方案已经变得越来越 ...

  3. 柯南君 :Oracle 分区技术 之 怎样支撑大数据操作?

    前段时间.看了罗女士( 资深技术顾问 - Oracle 中国 顾问咨询部)关于<大批量数据处理技术的演讲>视频.感觉受益良多,结合多年的知识积累,柯南君给大家分享一下: 交流内容: 一.O ...

  4. 话说C语言const用法

    const在C语言中算是一个比较新的描述符,我们称之为常量修饰符,意即其所修饰 的对象为常量(immutable). 我们来分情况看语法上它该如何被使用. 1.函数体内修饰局部变量. 例: void ...

  5. apache apr介绍

    APR(Apache portable Run-time libraries,Apache可移植运行库)的目的如其名称一样,主要为上层的应用程序提供一个可以跨越多操作系统平台使用的底层支持接口库.在早 ...

  6. 聊聊 Xcode 项目文件中的 project.pbxproj

    project.pbxproj 文件被包含于 Xcode 工程文件 *.xcodeproj 之中,存储着 Xcode 工程的各项配置参数.它本质上是一种旧风格的 Property List 文件,历史 ...

  7. GCD三种队列

    :dispatch_get_global_queue 后台执行队列 :dispatch_get_main_queue 主队列 :dispatch_queue_create("test&quo ...

  8. 【Mood-4】心静是一门艺术

    到现在工作还没有着落,心里面反而比以前平静,以前也知道自己的水平 属于一瓶不满,半瓶咣当的那种情况,但是那时候的自己总是觉得自己的综合水平可能会弥补一下自己在技术上的缺失,但是,现在看来,太过于自信, ...

  9. 函数参数选项的处理getopt getopt_long getopt_long_only

    转载:http://blog.chinaunix.net/uid-20321537-id-1966849.html   在头文件中int getopt(int argc,char *argv[], c ...

  10. cocoapods 卸载,重装,高版本的使用

    今天清理下电脑,发现自己电脑上的cocoapods经常出现的一个问题就是一些经常用的第三方库cocoapods搜不到,比如SDWebImage,然后就鼓捣了一下 $pos list 命令发现M 以后的 ...