美文网首页
自定义UINavigationController

自定义UINavigationController

作者: ios小正太 | 来源:发表于2017-02-14 21:41 被阅读0次

创建一个UINavigationController类

然后自定义返回按钮

和手势

- (void)viewDidLoad {

   [super viewDidLoad];

   // Do any additional setup after loading the view.

   //手势设置

   self.interactivePopGestureRecognizer.delegate =self;

   //设置导航背景图片

   [self.navigationBar setBackgroundImage:[UIImage imageNamed:@"navigationbarBackgroundWhite"] forBarMetrics:UIBarMetricsDefault];

}

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

{

   if (self.childViewControllers.count>0)

   {

       UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];

       [backButton setImage:[UIImage imageNamed:@"个人设置--返回@2x"] forState:UIControlStateNormal];

//        [backButton setImage:[UIImage imageNamed:@"navigationButtonReturnClick"] forState:UIControlStateHighlighted];

//        [backButton setTitle:@"返回" forState:UIControlStateNormal];

//        [backButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];

//        [backButton setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted];

       [backButton sizeToFit];

       backButton.contentEdgeInsets = UIEdgeInsetsMake(0, -20, 0, 0);

       [backButton addTarget:self action:@selector(backClick) forControlEvents:UIControlEventTouchUpInside];

       viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];

       //隐藏底部TabBar

       viewController.hidesBottomBarWhenPushed = YES;

   }

   [super pushViewController:viewController animated:animated];

}

- (void)backClick

{

[self popViewControllerAnimated:YES];

}

-(BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer

{

   //这是控制bgu的 判断

//    if (self.childViewControllers.count == 1)

//    {

//        return NO;

//    }

//    return YES;

   //手势何时有效  当导航控制器的子控制器个数 > 1 时 有效

   return self.childViewControllers.count > 1;

}

   

相关文章

网友评论

      本文标题:自定义UINavigationController

      本文链接:https://www.haomeiwen.com/subject/kgjfwttx.html