ios 自定义导航栏,开启侧滑返回手势
自定义一个常用ListViewController
.h文件
#import <UIKit/UIKit.h> @interface ListViewController : UIViewController -(void)diquButtonClick; @end
.m文件
//
// ListViewController.m
// OuLianWang
//
// Created by allenariel on 15/6/24.
// Copyright (c) 2015年 皇室美家. All rights reserved.
// #import "ListViewController.h"
#import "ZDYTabBarController.h"
#import "GustomViewController.h" @interface ListViewController () @end @implementation ListViewController
-(void)loadView
{
[super loadView];
[self deplyNavigationController];
self.view.backgroundColor=XZColor(, , );
}
- (void)viewDidLoad
{ [super viewDidLoad];
[self deplyNavigationController]; // [self hideTabBar]; }
-(void)viewWillAppear:(BOOL)animated
{ ZDYTabBarController *tabBar=(ZDYTabBarController*)self.navigationController.tabBarController;
tabBar.zqTabBar.hidden=YES; }
-(void)hideTabBar
{
ZDYTabBarController *tabBar=(ZDYTabBarController*)self.navigationController.tabBarController;
tabBar.zqTabBar.hidden=YES;
// self.view.backgroundColor=ZQColor(232, 232, 232); }
-(void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
ZDYTabBarController *tabBar=(ZDYTabBarController*)self.navigationController.tabBarController;
tabBar.zqTabBar.hidden=NO;
} #pragma mark-------配置导航栏 -(void)deplyNavigationController
{
GustomViewController *navi = [GustomViewController new];
self.navigationController.navigationBar.barTintColor=XZColor(,,);
[self.navigationController.navigationBar setTitleTextAttributes:@{NSFontAttributeName:[UIFont boldSystemFontOfSize:],
NSForegroundColorAttributeName:[UIColor whiteColor]}];
UIButton *diqubutton=[UIButton buttonWithType:UIButtonTypeCustom];
[diqubutton setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
[diqubutton addTarget:self action:@selector(diquButtonClick) forControlEvents:UIControlEventTouchUpInside];
diqubutton.titleLabel.font=[UIFont boldSystemFontOfSize:];
diqubutton.frame=CGRectMake(, ,,);
UIBarButtonItem *leftbutton=[[UIBarButtonItem alloc]initWithCustomView:diqubutton]; // 调整 leftBarButtonItem 在 iOS7 下面的位置
if(([[[UIDevice currentDevice] systemVersion] floatValue]>=7.0?:)) {
UIBarButtonItem *negativeSpacer = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace
target:nil action:nil];
negativeSpacer.width = -;//这个数值可以根据情况自由变化
self.navigationItem.leftBarButtonItems = @[negativeSpacer, leftbutton];
}
else self.navigationItem.leftBarButtonItem = leftbutton; self.tabBarController.tabBar.hidden=YES;
}
-(void)diquButtonClick
{
[self.navigationController popViewControllerAnimated:YES]; }
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} /*
#pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/ @end
自定义GuestomViewController,
.m
//
// GustomViewController.m
// 暇课
//
// Created by mac on 15/12/16.
// Copyright © 2015年 暇课. All rights reserved.
// #import "GustomViewController.h" @interface GustomViewController ()<UINavigationControllerDelegate, UIGestureRecognizerDelegate> @end @implementation GustomViewController - (instancetype)initWithRootViewController:(UIViewController *)rootViewController
{
if (self = [super initWithRootViewController:rootViewController]) {
// 设置navigationBar的背景颜色,根据需要自己设置
self.navigationBar.barTintColor = XZColor(,,);
// 设置navigationBar是否透明,不透明的话会使可用界面原点下移(0,0)点为导航栏左下角下方的那个点
self.navigationBar.translucent = NO;
// 设置navigationBar是不是使用系统默认返回,默认为YES
self.interactivePopGestureRecognizer.enabled = YES;
// 创建一个颜色,便于之后设置颜色使用
UIColor * color = [UIColor whiteColor];
// 设置navigationBar元素的背景颜色,不包括title
self.navigationBar.tintColor = color;
// 设置navigationController的title的字体颜色
NSDictionary * dict=[NSDictionary dictionaryWithObject:color forKey:NSForegroundColorAttributeName];
self.navigationBar.titleTextAttributes = dict; self.navigationBar.barTintColor=XZColor(,,);
[self.navigationController.navigationBar setTitleTextAttributes:@{NSFontAttributeName:[UIFont boldSystemFontOfSize:],
NSForegroundColorAttributeName:[UIColor whiteColor]}];
UIButton *diqubutton=[UIButton buttonWithType:UIButtonTypeCustom];
[diqubutton setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
[diqubutton addTarget:self action:@selector(diquButtonClick) forControlEvents:UIControlEventTouchUpInside];
diqubutton.titleLabel.font=[UIFont boldSystemFontOfSize:];
diqubutton.frame=CGRectMake(, ,,);
UIBarButtonItem *leftbutton=[[UIBarButtonItem alloc]initWithCustomView:diqubutton]; // 调整 leftBarButtonItem 在 iOS7 下面的位置
if(([[[UIDevice currentDevice] systemVersion] floatValue]>=7.0?:)) {
UIBarButtonItem *negativeSpacer = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace
target:nil action:nil];
negativeSpacer.width = -;//这个数值可以根据情况自由变化
self.navigationItem.leftBarButtonItems = @[negativeSpacer, leftbutton];
}
else self.navigationItem.leftBarButtonItem = leftbutton; self.tabBarController.tabBar.hidden=YES;
} return self;
} //- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
//{
// // fix 'nested pop animation can result in corrupted navigation bar'
// if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
// self.interactivePopGestureRecognizer.enabled = NO;
// }
//
// [super pushViewController:viewController animated:animated];
//}
//
//- (void)navigationController:(UINavigationController *)navigationController
// didShowViewController:(UIViewController *)viewController
// animated:(BOOL)animated
//{
// if ([navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
// navigationController.interactivePopGestureRecognizer.enabled = YES;
// }
//} - (void)viewDidLoad {
[super viewDidLoad]; // 为self创建弱引用对象
__weak typeof (self) weakSelf = self;
if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
self.interactivePopGestureRecognizer.delegate = weakSelf;
}
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} /*
#pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/ @end
完成~
ios 自定义导航栏,开启侧滑返回手势的更多相关文章
- iOS-自定义导航栏后侧滑返回功能失效
iPhone有一个回退按钮在所有的导航条上.这是一个简单的没有文字箭头. 在一开始写项目的时候,就要做好一个准备,导航栏是自定义还是使用系统的,后期有什么改动,有什么比较特殊的需求.当然这些在更改需求 ...
- iOS 自定义导航栏笔记
一.UINavigationBar的结构 导航栏几乎是每个页面都会碰到的问题,一般两种处理方式:1.隐藏掉不显示 2.自定义 1. 添加导航栏 TestViewController * mainVC ...
- ios之自定义导航栏上的返回按钮
导航栏的按钮,右边的按钮是可以自己随意添加的.但左边的返回按钮怎么定制?你会说,添加一个自己的按钮呗!你可以试试看,这样行不行. 正确的答案是重载UINavigationController类的pus ...
- 第十三篇、Swift_Nav自定义返回按钮后或者隐藏导航栏,Pop返回手势失效的解决方法 Pop全局返回添加的方法
边缘的pop返回手势: override func viewDidLoad() { super.viewDidLoad() view.backgroundColor = UIColor.purple ...
- iOS 自定义导航栏 和状态栏
一.更改状态栏颜色 (StatusBar) 就是比如导航栏是红色的状态栏是绿色的. 要实现这样的效果其实很简单,就是添加一个背景view. 简单的实现过程如下: 1 // 设置导航颜色 可用 2 [s ...
- IOS 自定义导航栏背景
//- (void)setBackgroundImage:(UIImage *)backgroundImage forBarMetrics:(UIBarMetrics)barMetrics NS_AV ...
- iOS 自定义导航栏
参考链接:https://blog.csdn.net/huanglinxiao/article/details/100537988 demo下载地址:https://github.com/huangx ...
- iOS学习—— UINavigationController的返回按钮与侧滑返回手势的研究
侧滑返回手势是从iOS7开始增加的一个返回操作,经历了两年时间估计iPhone用户大部分都已经忽略了屏幕左上角那个碍眼的back按钮了.之前在网上搜过有关侧滑手势的技术博客,发现大多比较散乱,甚至有很 ...
- IOS 改变导航栏返回按钮的标题
IOS 改变导航栏返回按钮的标题 下午又找到了一个新的方法 这个方法不错 暂时没有发现异常的地方. 新写的App中需要使用UINavigationController对各个页面进行导航,但由于第一 ...
随机推荐
- CodeForces - 1C:Ancient Berland Circus (几何)
Nowadays all circuses in Berland have a round arena with diameter 13 meters, but in the past things ...
- sql split函数
--DROP FUNCTION F_SQLSERVER_SPLIT GO CREATE FUNCTION F_SQLSERVER_SPLIT(@Long_str varchar(8000),@spli ...
- BZOJ5372: [Pkusc2018]神仙的游戏
BZOJ5372: [Pkusc2018]神仙的游戏 https://lydsy.com/JudgeOnline/problem.php?id=5372 分析: 如果\(len\)为\(border\ ...
- NOIp2018集训test-10-18 (bike day4)
这是一套简单题,这几天的考试让bike老爷感觉很绝望,说实话我也确实不知道还能怎么更简单了. 这几天的题换做llj.sxy应该都能轻松AK吧,至少随便考个250+应该不是问题吧,我越来越觉得觉得我跟他 ...
- Operating System-进程/线程内部通信-竞争条件(Race Conditions)
从本文开始介绍进程间的通信,进程间通信遇到的问题以及方式其实和线程之间通信是一致的,所以进程间通信的所有理论知识都可以用在线程上,接下来的系列文章都会以进程之间的通信为模版进行介绍,本文主要内容: 进 ...
- Operating System-Thread(2) Multi-Process-Parallel vs Multi-Thread-Parallel
本文主要介绍线程的模型 一.Multi-Process-Parallel vs Multi-Thread-Parallel 多进程的并行:CPU在多个进程之间进行切换,系统给人一种多个进程在并行执行的 ...
- BZOJ1012:[JSOI2008]最大数
浅谈栈:https://www.cnblogs.com/AKMer/p/10278222.html 题目传送门:https://lydsy.com/JudgeOnline/problem.php?id ...
- bzoj 2093 [Poi2010]Frog——滑动窗口
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2093 找第k近的可以用一个含k个元素的滑动窗口来实现. 卡空间也还行,但卡时间.不要预处理倍 ...
- poj 1519 Digital Roots (计算根数字)
一.Description The digital root of a positive integer is found by summing the digits of the integer. ...
- Express Route的配置
ExpressRoute在中国已经Preview了. 本篇文章讲介绍ExpressRoute如何配置. Express Route的逻辑拓扑结构: 在配置Express Route之前,需要做VLAN ...