依赖于第三方的框架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. Codeforces Round #310 (Div. 1) B. Case of Fugitive set

    B. Case of Fugitive Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/555/p ...

  2. TP复习17

    三大自动,自动创建,自动验证,自动完成

  3. ios开发——实用技术篇Swift篇&照片选择

    照片选择 // MARK: - 选择照片 /*----- 选择照片 ------*/ @IBAction func addImageButtonClick() { let actionSheet = ...

  4. Progressive JPEG

    和Baseline一遍扫描不同,Progressive JPEG文件包含多次扫描,这些扫描顺寻的存储在JPEG文件中.打开文件过程中,会先显示整个图片的模糊轮廓,随着扫描次数的增加,图片变得越来越清晰 ...

  5. tachyon with hadoop

    hadoop2.2.0 jdk1.7 tachyon0.5.0 无zookeeper tachyon和hadoop都是伪分布式模式 1.修改core-site.xml文件 <property&g ...

  6. C# 创建线程的简单方式:异步委托 .

    定义一个委托调用的方法:TakesAWhile //定义委托要引用的方法 private static int TakesAWhile(int data, int ms) { Console.Writ ...

  7. Conversions

    Problem Description Conversion between the metric and English measurement systems is relatively simp ...

  8. setsockopt

    1.closesocket(一般不会立即关闭而经历TIME_WAIT的过程)后想继续重用该socket:BOOL bReuseaddr=TRUE;setsockopt(s,SOL_SOCKET ,SO ...

  9. [转]epoll技术

    在linux的网络编程中,很长的时间都在使用select来做事件触发.在linux新的内核中,有了一种替换它的机制,就是epoll. 相比于select,epoll最大的好处在于它不会随着监听fd数目 ...

  10. iOS - 混合开发

    5.oc 与 js 混合开发 PhoneGap 专门做混合开发的,已经被另一个公司收购. WebViewJavascriptBridge 国内用的比较多 混合开发的好处:跨平台性.H5开发的时间成本, ...