#import "JHNav.h"
@interface JHNav ()
@end
@implementation JHNav
- (void)viewDidLoad {
[super viewDidLoad];
__weakJHNav*weakSelf =self;
if([selfrespondsToSelector:@selector(interactivePopGestureRecognizer)])
{
self.interactivePopGestureRecognizer.delegate = weakSelf;
self.delegate= weakSelf;
}
if(@available(iOS11.0, *)) {
UIImage *backButtonImage = [[[UIImage imageNamed:@"返回"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] resizableImageWithCapInsets:UIEdgeInsetsMake(0,16,0, 0)];
self.navigationBar.backIndicatorImage = backButtonImage;
self.navigationBar.backIndicatorTransitionMaskImage = backButtonImage;
[[UIBarButtonItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor clearColor]}forState:UIControlStateNormal];//将title 文字的颜色改为透明
[[UIBarButtonItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor clearColor]}forState:UIControlStateHighlighted];//将title 高亮文字的颜色改为透明
}else{
[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0.0f,-60.0f) forBarMetrics:UIBarMetricsDefault];
[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0.0f,-60.0f) forBarMetrics:UIBarMetricsCompact];
//导航栏 返回键
UIImage *backButtonImage = [[[UIImage imageNamed:@"返回"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] resizableImageWithCapInsets:UIEdgeInsetsMake(0,16,0, 0)];
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:backButtonImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:backButtonImage forState:UIControlStateNormal barMetrics:UIBarMetricsCompact];
[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0.0f,-60.0f) forBarMetrics:UIBarMetricsDefault];//导航栏 返回键文字位置
}
}
- (id)initWithRootViewController:(UIViewController*)rootViewController
{
self= [superinitWithRootViewController:rootViewController];
if(self) {
// Custom initialization
}
return self;
}
- (void)pushViewController:(UIViewController*)viewController animated:(BOOL)animated
{
if( [selfrespondsToSelector:@selector(interactivePopGestureRecognizer)] && animated ==YES)
{
self.interactivePopGestureRecognizer.enabled = NO;
}
[superpushViewController:viewControlleranimated:animated];
}
- (NSArray*)popToRootViewControllerAnimated:(BOOL)animated
{
if( [selfrespondsToSelector:@selector(interactivePopGestureRecognizer)] && animated ==YES)
{
self.interactivePopGestureRecognizer.enabled = NO;
}
return [super popToRootViewControllerAnimated:animated];
}
- (NSArray*)popToViewController:(UIViewController*)viewController animated:(BOOL)animated
{
if( [selfrespondsToSelector:@selector(interactivePopGestureRecognizer)] )
{
self.interactivePopGestureRecognizer.enabled = NO;
}
return[superpopToViewController:viewControlleranimated:animated];
}
#pragma mark UINavigationControllerDelegate
- (void)navigationController:(UINavigationController*)navigationController
didShowViewController:(UIViewController*)viewController
animated:(BOOL)animate
{
if([selfrespondsToSelector:@selector(interactivePopGestureRecognizer)])
{
self.interactivePopGestureRecognizer.enabled = YES;
}
}
-(BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer*)gestureRecognizer
{
if ( gestureRecognizer == self.interactivePopGestureRecognizer )
{
if ( self.viewControllers.count < 2 || self.visibleViewController == [self.viewControllers objectAtIndex:0] )
{
returnNO;
}
}
return 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
网友评论