添加全屏侧滑返回
.获取到系统的pop返回手势
.获取pop在哪个view上
.获取target,action
.自定义UIPanGestureRecognizer

//1.获取手势

guard let pop = interactivePopGestureRecognizer else { return }

//2.获取手势的view

guard let gesView = pop.view else { return }

//3.获取target/action

let targets = pop.value(forKey: "_targets") as? [NSObject]

let targetObj = targets?.first

if targetObj == nil { return }

//3.1.target

guard let target = targetObj?.value(forKey: "target") else { return }

//3.2.取出Action

let action = Selector(("handleNavigationTransition:"))

//4.自己创建手势

let pan = UIPanGestureRecognizer(target: target, action: action)

gesView.addGestureRecognizer(pan)

1.关于导航栏左右两边的按钮

.隐藏导航栏上的返回字体
//Swift
UIBarButtonItem.appearance().setBackButtonTitlePositionAdjustment(UIOffsetMake(, -), forBarMetrics: .Default)
//OC
[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(, -) forBarMetrics:UIBarMetricsDefault]; //设置导航栏右边有2个按钮
UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithCustomView:view];
self.navigationItem.rightBarButtonItem = item; 系统默认的rightBarButtonItem边距
self.navigationItem.leftBarButtonItem.imageInsets = UIEdgeInsetsMake(,-,,);
self.navigationItem.rightBarButtonItem.imageInsets = UIEdgeInsetsMake(,-,,); //使左边导航栏按钮位置更加左边一点
{
UIView *left = [[UIView alloc] init];
left.frame = CGRectMake(, , , );
UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithCustomView:left]; //使导航栏按钮位置更加左边或者右边
UIBarButtonItem *nagetiveSpacer = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
nagetiveSpacer.width = -;//这个值可以根据自己需要自己调整 self.navigationItem.leftBarButtonItems = @[nagetiveSpacer,item];
} UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithCustomView:back];
item.width = -;

2.修改标题

//标题颜色
self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName : [UIColor someColor]} //设置了导航条背景颜色,会导致按钮标题颜色改变,通过以下方法修改
导航栏子控件颜色
self.navigationController.navigationBar.tintColor = [UIColor someColor]; 修改导航条背景颜色
self.navigationController.navigationBar.barTintColor = [UIColor colorWithHexString:@"#2295f2"];

//设置导航控制器标题的颜色和字体大小等

NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:

[UIColor whiteColor],NSForegroundColorAttributeName,

[UIFont systemFontOfSize:17],NSFontAttributeName,nil];

[self.navigationController.navigationBar setTitleTextAttributes:attributes];

3.在滑动过程中隐藏navigationbar

() 像safari
self.navigationController.hidesBarsOnSwipe = YES;
()
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
CGFloat offsetY = scrollView.contentOffset.y + __tableView.contentInset.top;
CGFloat panTranslationY = [scrollView.panGestureRecognizer translationInView:self.tableView].y;
if (offsetY > ) {
if (panTranslationY > )
{
//下滑趋势,显示
[self.navigationController setNavigationBarHidden:NO animated:YES];
} else {
//上滑趋势,隐藏
[self.navigationController setNavigationBarHidden:YES animated:YES];
}
} else {
[self.navigationController setNavigationBarHidden:NO animated:YES];
}
}
这里的offsetY > 64只是为了在视图滑过navigationBar的高度之后才开始处理,防止影响展示效果。panTranslationY是scrollView的pan手势的手指位置的y值,可能不是太好,因为panTranslationY这个值在较小幅度上下滑动时,可能都为正或都为负,这就使得这一方式不太灵敏.
().当我们的手离开屏幕时候隐藏
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset
{
if(velocity.y > )
{
[self.navigationController setNavigationBarHidden:YES animated:YES];
} else {
[self.navigationController setNavigationBarHidden:NO animated:YES];
}
}
velocity.y这个量,在上滑和下滑时,变化极小(小数),但是因为方向不同,有正负之分,这就很好处理了。

4.设置导航栏透明度

//第一种navigationBar根据滑动距离的渐变色实现
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
CGFloat offsetToShow = 200.0;//滑动多少就完全显示
CGFloat alpha = - (offsetToShow - scrollView.contentOffset.y) / offsetToShow;
[[self.navigationController.navigationBar subviews] objectAtIndex:].alpha = alpha;
} //第二种
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
CGFloat offsetToShow = 200.0;
CGFloat alpha = - (offsetToShow - scrollView.contentOffset.y) / offsetToShow; [self.navigationController.navigationBar setShadowImage:[UIImage new]];
[self.navigationController.navigationBar setBackgroundImage:[self imageWithColor:[[UIColor orangeColor]colorWithAlphaComponent:alpha]] forBarMetrics:UIBarMetricsDefault];
} //生成一张纯色的图片
- (UIImage *)imageWithColor:(UIColor *)color
{
CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [color CGColor]);
CGContextFillRect(context, rect);
UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext(); return theImage;
}
设置导航栏透明
//方法一:设置透明度
[[[self.navigationController.navigationBar subviews]objectAtIndex:] setAlpha:0.1];
//方法二:设置背景图片
/**
* 设置导航栏,使其透明
*
*/
- (void)setNavigationBarColor:(UIColor *)color targetController:(UIViewController *)targetViewController{
//导航条的颜色 以及隐藏导航条的颜色targetViewController.navigationController.navigationBar.shadowImage = [[UIImage alloc]init];
CGRect rect=CGRectMake(0.0f, 0.0f, 1.0f, 1.0f); UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetFillColorWithColor(context, [color CGColor]); CGContextFillRect(context, rect);
UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); [targetViewController.navigationController.navigationBar setBackgroundImage:theImage forBarMetrics:UIBarMetricsDefault];
} //3
//设置一张空的图片
[self.navigationController.navigationBar setBackgroundImage:[[UIImage alloc]init] forBarMetrics:UIBarMetricsDefault];
//清除边框,设置一张空的图片(隐藏底部阴影条,传递一个空图片的UIImage对象),底部的黑线
[self.navigationController.navigationBar setShadowImage:[[UIImage alloc]init]];
//是否透明
self.navigationController.navigationBar.translucent = YES;

5.滑动返回手势

//关闭navigationController的滑动返回手势
//第一种
self.navigationController.interactivePopGestureRecognizer.enabled = NO; //第二种
id target = self.navigationController.interactivePopGestureRecognizer.delegate;
UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:target action:nil];
[self.view addGestureRecognizer:pan]; //解决导航控制器pop手势失效
self.interactivePopGestureRecognizer.delegate = self; - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
{
// 手势何时有效 : 当导航控制器的子控制器个数 > 1就有效
return self.childViewControllers.count > ;
}

6.导航栏的隐藏显示问题(正确的姿势)

.// 设置导航控制器的代理为self
self.navigationController.delegate = self; .<UINavigationControllerDelegate> .// 将要显示控制器
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
// 判断要显示的控制器是否是自己
BOOL isShowHomePage = [viewController isKindOfClass:[self class]]; [self.navigationController setNavigationBarHidden:isShowHomePage animated:YES];
}

7.修改pop回来的页面

#warning  写在 C 的 viewDidLoad() 方法中
//A push 到 B, B push 到 C, C pop 到 D,D 再 pop到 A
// 建立可变拷贝对象,然后进行替换操作
NSMutableArray *navChildMArr = [self.navigationController.childViewControllers mutableCopy];
[navChildMArr replaceObjectAtIndex: withObject:D]; // 当然,最后再将替换后的数组赋值回去不要忘了
[self.navigationController setViewControllers:navChildMArr animated:YES]; 自定义导航栏:https://github.com/zhangjie579/IWNavigationController

8.关于push,pop,model,dimiss

遍历popToViewController跳转的控制器,然后跳到指定位置
for (int i = ; i<self.navigationController.viewControllers.count; i++) { UIViewController * controller = self.navigationController.viewControllers[i]; if ([controller isKindOfClass:InformMainViewController.class]) { InformMainViewController * vc = (InformMainViewController *)controller; [self.navigationController popToViewController:vc animated:YES]; break; }
} pop回指定控制器 . NSArray *viewControllers=[self.navigationController viewControllers];
. UIViewController *controller=[viewControllers objectAtIndex:];
. [self.navigationController popToViewController:controller animated:YES]; .关于push,pop,model,dimiss
.注意:如果用stroyboard的话,要拉线,不然可能会出现不了界面!!!
[self performSegueWithIdentifier:@"MyApply-To-FlowDetail" sender:nil];
//跳转前传值
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"MyApply-To-FlowDetail"]) {
FlowDetailController * controller = segue.destinationViewController;
if (_bool_fromApply) {
controller.flow_id = _flow_id;
}
else
{
controller.flow_id = _flowInfoModel.id;
}
controller.delegate = self;
}
}
.第二种方法
UIStoryboard *story = [UIStoryboard storyboardWithName:@"My" bundle:nil];
MyEnterCompanyNameController *vc = (MyEnterCompanyNameController *)[story instantiateViewControllerWithIdentifier:@"MyEnterCompanyName"]; [self.navigationController pushViewController:vc animated:YES]; .设置转场动画modalTransitionStyle .系统的
ForgetNameViewController *vc = [[ForgetNameViewController alloc] init];
    vc.vcType = ViewControllerTypeFindName;
//    [self.navigationController pushViewController:vc animated:YES];
   
    IWNavigationController *nav = [[IWNavigationController alloc] initWithRootViewController:vc];
    [IWNavigationController setupWithType:IWNavTypeWhite];

    //nav.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;//以屏幕中间x为轴旋转
    //nav.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;//直接进入页面,无动画效果
    nav.modalTransitionStyle = UIModalTransitionStylePartialCurl;//翻页
   
    [self presentViewController:nav animated:YES completion:nil];
.自定义的
    1.创建个CATransition动画
    2.将动画添加到self.view.window.layer,注意:千万别忘了window
    3.presentViewController的时候,animated要设置为no
    4.dissmiss的时候,animated也要设置为no,并且,也要添加对应的动画
CATransition *animation = [CATransition animation];
    [animation setDuration:0.5];
    [animation setType:kCATransitionPush];
    [animation setSubtype:kCATransitionFromRight];
    [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
   
    [self.view.window.layer addAnimation:animation forKey:@"LoginViewController"];                   //  添加动作
   
    ForgetNameViewController *vc = [[ForgetNameViewController alloc] init];
    vc.vcType = ViewControllerTypeFindName;
   
    IWNavigationController *nav = [[IWNavigationController alloc] initWithRootViewController:vc];
    [IWNavigationController setupWithType:IWNavTypeWhite];
   
    [self presentViewController:nav animated:NO completion:^{
        [self.view.window.layer removeAnimationForKey:@"LoginViewController"];
    }];

ios UINavigationController 导航栏的更多相关文章

  1. IOS 改变导航栏返回按钮的标题

    IOS 改变导航栏返回按钮的标题   下午又找到了一个新的方法 这个方法不错 暂时没有发现异常的地方. 新写的App中需要使用UINavigationController对各个页面进行导航,但由于第一 ...

  2. iOS 11 导航栏 item 偏移问题 和 Swift 下 UIButton 设置 title、image 显示问题

    html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,bi ...

  3. iOS:视图切换的第二种方式:UINavigationController导航栏控制器

    UINavigationController:一个以栈的形式管理多视图的容器,负责子控制器之间的跳转.由于以栈的方式管理视图,各个视图的切换就是压栈和出栈操作,所以出栈后的视图会立即销毁. 介绍: & ...

  4. iOS UITableView表视图滚动隐藏UINavigationController导航栏

    UITableView 继承于UIScrollView 所以UIScrollView 的代理方法相同适用于UITableView 中 隐藏导航栏的方法为: self.navigationControl ...

  5. iOS设置导航栏样式(UINavigationController)

    //设置导航栏baritem和返回baiitem样式 UIBarButtonItem *barItem = [UIBarButtonItem appearance]; //去掉返回按钮上的字 [bar ...

  6. 【转】【iOS】导航栏那些事儿

    原文网址:http://www.jianshu.com/p/f797793d683f 参考文章 navigationItem UINavigationItem UINavigationBar UIBa ...

  7. IOS UINavigationController 导航控制器

    /** 导航控制器掌握: 1.创建导航控制器 UINavigationController *nav = [[UINavigationController alloc] initWithRootVie ...

  8. iOS 设置导航栏之二(设置导航栏的颜色、文字的颜色、左边按钮的文字及颜色)

                      #import <UIKit/UIKit.h> @interface AppDelegate : UIResponder <UIApplicati ...

  9. iOS 设置导航栏的颜色和导航栏上文字的颜色

    #import <UIKit/UIKit.h> @interface AppDelegate : UIResponder <UIApplicationDelegate> @pr ...

随机推荐

  1. .equal()和==的区别

    1.首先,equal和==最根本的区别在于equal是一个方法,而==是一个运算符. 2.一般来说,==运算符比较的是在内存中的物理地址,.equal()比较的是哈希算法值是否相等(即hashcode ...

  2. 吴裕雄--天生自然 JAVASCRIPT开发学习:Date(日期) 对象

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  3. MySQL空洞问题解决

    原因:Mysql对于BLOB/TEXT值在执行大量删除操作时可能会引起空洞.空洞就是数据虽然删除了,但是依然占用服务器物理空间,会导致性能底下. 解决办法:定期使用OPTIMIZE TABLE进行碎片 ...

  4. Express+MySQL实现图片上传到服务器并把路径保存到数据库中

    demo准备:mysql5.7.20 express4.0 处理图片文件的中间件Multer 先搭建服务器并展示html页面 const express = require("express ...

  5. 命令行的操作——cd

    初学命令行,总是提示找不到有关的文件,当时的我啥也不知道,最后就很惨,啥也找不到 后来就只好自己上网找资料了 以下博文改编自小佳的博客 在需要处理不同路径下的文件的时候,经常要在命令行模式下切换目录, ...

  6. Django框架(七):模型(三) 关联、模型类的属性

    1. 关联 1.1 模型类关系 关系型数据库的关系包括三种类型: ForeignKey:一对多,将字段定义在多的一端中. ManyToManyField:多对多,将字段定义在任意一端中. OneToO ...

  7. NodeJS框架一览

    NodeJS 框架一览 Express 当你使用Node.js构建web应用程序时, Express通常被视为事实上的Web服务器.它的哲学(一个可以使用中间件包扩展的简约核心)是大多数Node.js ...

  8. gbdt在回归方面的基本原理以及实例并且可以做分类

    对书法的热爱,和编译器打数学公式很艰难,就这样的正例自己学过的东西,明天更新gbdt在分类方面的应用. 结论,如果要用一个常量来预测y,用log(sum(y)/sum(1-y))是一个最佳的选择. 本 ...

  9. 17.3.12--uillib模块

    1---uillib是python标准库中最常用的一个python网络应用资源访问的模块,他可以让你像访问文本一样,读取网页的内容 它的作用是访问一些不需要验证的网络资源和cookie等 uillib ...

  10. 吴裕雄--天生自然TensorFlow2教程:维度变换

    图片视图 [b, 28, 28] # 保存b张图片,28行,28列(保存数据一般行优先),图片的数据没有被破坏 [b, 28*28] # 保存b张图片,不考虑图片的行和列,只保存图片的数据,不关注图片 ...