1、一般导航条标题的字体setTitleTextAttribute和背景颜色setBackgroundImage都是统一的,可以在load方法中使用appearanceWhenContainedIn统一设置
2、一般导航条的返回按钮需要自定义,一般除了栈底控制器有导航条,其他控制器都需要隐藏底部的条,可以重写pushViewController:animated:方法,在该方法中实现该功能
3、导航控制器右滑返回效果(触摸屏幕的任意一点,向右滑动返回)
UIViewController
--navigationItem
leftBarButtonItem | leftBarButtonItems
NSString title | UIView titleView
rightBarButtonItem | rightBarButtonItems
backBarButtonItem
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
#import "BWNavigationController.h"
#import "UIBarButtonItem+Item.h"
@interface BaseNavigationController () <UIGestureRecognizerDelegate>
@end
@implementation BWNavigationController
+ ( void )load {
[super load];
UINavigationBar *navigationBar = [UINavigationBar appearanceWhenContainedIn:self, nil];
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
dict[NSFontAttributeName] = [UIFont boldSystemFontOfSize:20];
[navigationBar setTitleTextAttributes:dict];
[navigationBar setBackgroundImage:[UIImage imageNamed:@ "navigationbarBackgroundWhite" ] forBarMetrics:UIBarMetricsDefault];
}
- ( void )viewDidLoad {
[super viewDidLoad];
// 屏幕边缘滑动(只能在屏幕的边缘才能触发该手势,不能在屏幕的任意一点触发该手势)
UIScreenEdgePanGestureRecognizer *edgePanGestureRecognizer = (UIScreenEdgePanGestureRecognizer *)self.interactivePopGestureRecognizer;
// 滑动手势(禁用系统自带的屏幕边缘滑动手势,使用自定义的滑动手势目的就是达到触摸屏幕上的任意一点向右滑动都能实现返回的效果)
UIPanGestureRecognizer *panGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:edgePanGestureRecognizer.delegate action:@selector(handleNavigationTransition:)];
panGestureRecognizer.delegate = self;
[self.view addGestureRecognizer:panGestureRecognizer];
// 禁用系统的屏幕边缘滑动手势
edgePanGestureRecognizer.enabled = NO;
}
// 是否允许触发手势,如果是根视图控制器则不需要
- ( BOOL )gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
return self.childViewControllers.count > 1;
}
- ( void )pushViewController:(UIViewController *)viewController animated:( BOOL )animated {
// 统一设置返回按钮
NSInteger count = self.childViewControllers.count;
if (count > 0) {
viewController.hidesBottomBarWhenPushed = YES;
viewController.navigationItem.leftBarButtonItem = [UIBarButtonItem backBarButtonItemWithImage:[UIImage imageNamed:@ "navigationButtonReturn" ] highlightImage:[UIImage imageNamed:@ "navigationButtonReturnClick" ] tagert:self action:@selector(back) title:@ "返回" ];
}
[super pushViewController:viewController animated:animated];
}
- ( void )back {
[self popViewControllerAnimated:YES];
}
@end
|
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。