XMGOpenGLNavVc.m 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. //
  2. // XMGOpenGLNavVc.m
  3. // XMGOpenGLDrawPanel
  4. //
  5. // Created by wei zeng on 2019/5/7.
  6. // Copyright © 2019 wei zeng. All rights reserved.
  7. //
  8. #import "XMGOpenGLNavVc.h"
  9. @interface XMGOpenGLNavVc ()<UINavigationControllerDelegate>
  10. @end
  11. @implementation XMGOpenGLNavVc
  12. + (void)initialize{
  13. UIImage *bg = [UIImage imageNamed:@"navigationbarBackgroundWhite8"];
  14. UINavigationBar *bar = [UINavigationBar appearance];
  15. [bar setTintColor:[UIColor whiteColor]];
  16. [bar setBackgroundImage:bg forBarMetrics:UIBarMetricsDefault];
  17. [bar setBackgroundColor:[UIColor whiteColor]];
  18. [bar setTitleTextAttributes:@{NSFontAttributeName : [UIFont systemFontOfSize:15 weight:UIFontWeightRegular]}];
  19. UIFont *font = [UIFont systemFontOfSize:15 weight:UIFontWeightRegular];
  20. NSDictionary *textAttributes = @{
  21. NSFontAttributeName : font,
  22. NSForegroundColorAttributeName : [UIColor blackColor]
  23. };
  24. [[UINavigationBar appearance] setTitleTextAttributes:textAttributes];
  25. [[UINavigationBar appearance] setTintColor:[UIColor blackColor]];
  26. [[UINavigationBar appearance] setBarTintColor:kRGBColor(255, 255, 255)];
  27. }
  28. /*
  29. -(void)viewDidLoad{
  30. [super viewDidLoad];
  31. if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
  32. self.interactivePopGestureRecognizer.enabled = NO;
  33. }
  34. }
  35. */
  36. - (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
  37. {
  38. if (self.childViewControllers.count) {
  39. viewController.hidesBottomBarWhenPushed = YES;
  40. UIButton *button = [[UIButton alloc] init];
  41. [button setImage:[UIImage imageNamed:@"navigationButtonReturn"] forState:UIControlStateNormal];
  42. [button setImage:[UIImage imageNamed:@"navigationButtonReturnClick"] forState:UIControlStateHighlighted];
  43. button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
  44. //[button setTitle:@"返回" forState:UIControlStateNormal];
  45. [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  46. [button setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted];
  47. [button addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
  48. button.bounds = CGRectMake(0, 0, 30, 44);
  49. //[button sizeToFit];
  50. //button.contentEdgeInsets = UIEdgeInsetsMake(0, -5, 0, 0);
  51. button.titleLabel.font = [UIFont systemFontOfSize:15];
  52. viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
  53. }
  54. [[NSNotificationCenter defaultCenter] postNotificationName:@"hidddenBottomView" object:nil userInfo:@{@"jxmessage":@"1",@"my":@"1",@"gif":@"1"}];
  55. // [[NSNotificationCenter defaultCenter] postNotificationName:@"hidddenShowBottomView" object:nil];
  56. viewController.hidesBottomBarWhenPushed=YES;
  57. [super pushViewController:viewController animated:animated];
  58. NSLog(@"aaaa %zd",self.childViewControllers.count);
  59. }
  60. -(void)back{
  61. [self popViewControllerAnimated:YES];
  62. }
  63. - (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated{
  64. if ([navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
  65. navigationController.interactivePopGestureRecognizer.enabled = YES;
  66. }
  67. if (navigationController.viewControllers.count == 1) {
  68. navigationController.interactivePopGestureRecognizer.enabled = NO;
  69. }
  70. }
  71. //- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
  72. //{
  73. // // 手势何时有效 : 当导航控制器的子控制器个数 > 1就有效
  74. // return self.childViewControllers.count > 1;
  75. //}
  76. @end