导航控制器ZJBaseNaviController+导航栏返回按钮点击事件拦截


#import <UIKit/UIKit.h>


@interface ZJBaseNaviController : UINavigationController


@end


#import "ZJBaseNaviController.h"

#import "UIViewController+BackButtonHandler.h"

@interface ZJBaseNaviController ()<UIGestureRecognizerDelegate>

@end


@implementation ZJBaseNaviController

#pragma mark - 初始化

/**

 只加载一次

 */

+(void)load{

    UINavigationBar *navBar = [UINavigationBar appearance];

    // 导航栏颜色

    navBar.barTintColor = [UIColor whiteColor];

    // 导航栏是否有透明效果

    navBar.translucent = NO;

    // 导航栏分割线

    navBar.shadowImage = [UIImage new];

    // 导航栏字体颜色

    NSMutableDictionary * param = [NSMutableDictionary new];

    [param setObject:[UIFont systemFontOfSize:17] forKey:NSFontAttributeName];

    [param setObject:[UIColor redColor] forKey:NSForegroundColorAttributeName];

    [navBar setTitleTextAttributes:param];

}

- (void)viewDidLoad {

    [super viewDidLoad];

    // Do any additional setup after loading the view.

    // 滑动手势

    if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)]) {

        self.interactivePopGestureRecognizer.delegate = self;

    }

}

#pragma mark - UIGestureRecognizerDelegate

-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch

{

    //是否出发手势

    return self.childViewControllers.count > 1;

}


-(void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated{

    if(self.childViewControllers.count>0){

        viewController.navigationController.title = @"";

        viewController.hidesBottomBarWhenPushed = YES;

        CGRect tempFrame = CGRectMake(0, 0, 40, 40);

        UIButton * button = [[UIButton alloc] initWithFrame:tempFrame];

        [button setImageEdgeInsets:UIEdgeInsetsMake(0, -10, 0, 10)];

        [button setImage:[UIImage imageNamed:@"arrow_left"] forState:UIControlStateNormal];

        [button addTarget:self action:@selector(backBeforViewController) forControlEvents:UIControlEventTouchUpInside];

        UIBarButtonItem * leftItem = [[UIBarButtonItem alloc] initWithCustomView:button];

        viewController.navigationItem.leftBarButtonItem = leftItem;

    }

    [super pushViewController:viewController animated:animated];

}

-(void)backBeforViewController{

    BOOL shouldPop = YES;

    UIViewController * tempViewController = [self topViewController];

    if([tempViewController respondsToSelector:@selector(navigationShouldPopOnBackButton)]) {

        shouldPop = [tempViewController navigationShouldPopOnBackButton];

    }

    if(shouldPop){

        [self popViewControllerAnimated:YES];

    }

}

@end



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值