自界說導航掌握器: 將導航掌握器中通用的部門拿出來同一設置
1、普通導航條題目的字體setTitleTextAttribute和配景色彩setBackgroundImage都是同一的,可以在load辦法中應用appearanceWhenContainedIn同一設置
2、普通導航條的前往按鈕須要自界說,普通除棧底掌握器有導航條,其他掌握器都須要隱蔽底部的條,可以重寫pushViewController:animated:辦法,在該辦法中完成該功效
3、導航掌握器右滑前往後果(觸摸屏幕的隨意率性一點,向右滑動前往)
UIViewController
--navigationItem
leftBarButtonItem | leftBarButtonItems
NSString title | UIView titleView
rightBarButtonItem | rightBarButtonItems
backBarButtonItem
#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
以上就是本文的全體內容,願望對年夜家的進修有所贊助,也願望年夜家多多支撐本站。
【進修iOS自界說導航掌握器UINavigationController】的相關資料介紹到這裡,希望對您有所幫助! 提示:不會對讀者因本文所帶來的任何損失負責。如果您支持就請把本站添加至收藏夾哦!