Commit 866f3c84677da7692c04a078ca09881a32557ea9

Authored by zhangxiaowen
1 parent 833222df

no message

Example/CNLiveBalanceModule.xcodeproj/project.pbxproj
@@ -8,6 +8,7 @@ @@ -8,6 +8,7 @@
8 8
9 /* Begin PBXBuildFile section */ 9 /* Begin PBXBuildFile section */
10 008EDC6D9F59708FC31D66E2 /* Pods_CNLiveBalanceModule_Example.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DF1592377FBDD3732275DFDB /* Pods_CNLiveBalanceModule_Example.framework */; }; 10 008EDC6D9F59708FC31D66E2 /* Pods_CNLiveBalanceModule_Example.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DF1592377FBDD3732275DFDB /* Pods_CNLiveBalanceModule_Example.framework */; };
  11 + 08827AFE23A8B4AC00EBF18F /* UIViewController+NavigationBarHidden.m in Sources */ = {isa = PBXBuildFile; fileRef = 08827AFD23A8B4AC00EBF18F /* UIViewController+NavigationBarHidden.m */; };
11 08ADA66223A381E100072772 /* CNLiveBaseViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 08ADA66123A381E100072772 /* CNLiveBaseViewController.m */; }; 12 08ADA66223A381E100072772 /* CNLiveBaseViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 08ADA66123A381E100072772 /* CNLiveBaseViewController.m */; };
12 08CA954D23A4609F001B1A99 /* CNLiveWebView.m in Sources */ = {isa = PBXBuildFile; fileRef = 08CA954B23A4609F001B1A99 /* CNLiveWebView.m */; }; 13 08CA954D23A4609F001B1A99 /* CNLiveWebView.m in Sources */ = {isa = PBXBuildFile; fileRef = 08CA954B23A4609F001B1A99 /* CNLiveWebView.m */; };
13 08CA955023A47090001B1A99 /* CNLiveBaseNavigationController.m in Sources */ = {isa = PBXBuildFile; fileRef = 08CA954F23A47090001B1A99 /* CNLiveBaseNavigationController.m */; }; 14 08CA955023A47090001B1A99 /* CNLiveBaseNavigationController.m in Sources */ = {isa = PBXBuildFile; fileRef = 08CA954F23A47090001B1A99 /* CNLiveBaseNavigationController.m */; };
@@ -42,6 +43,8 @@ @@ -42,6 +43,8 @@
42 /* End PBXContainerItemProxy section */ 43 /* End PBXContainerItemProxy section */
43 44
44 /* Begin PBXFileReference section */ 45 /* Begin PBXFileReference section */
  46 + 08827AFC23A8B4AC00EBF18F /* UIViewController+NavigationBarHidden.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIViewController+NavigationBarHidden.h"; sourceTree = "<group>"; };
  47 + 08827AFD23A8B4AC00EBF18F /* UIViewController+NavigationBarHidden.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIViewController+NavigationBarHidden.m"; sourceTree = "<group>"; };
45 08ADA66023A381E100072772 /* CNLiveBaseViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CNLiveBaseViewController.h; sourceTree = "<group>"; }; 48 08ADA66023A381E100072772 /* CNLiveBaseViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CNLiveBaseViewController.h; sourceTree = "<group>"; };
46 08ADA66123A381E100072772 /* CNLiveBaseViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CNLiveBaseViewController.m; sourceTree = "<group>"; }; 49 08ADA66123A381E100072772 /* CNLiveBaseViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CNLiveBaseViewController.m; sourceTree = "<group>"; };
47 08CA954B23A4609F001B1A99 /* CNLiveWebView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CNLiveWebView.m; sourceTree = "<group>"; }; 50 08CA954B23A4609F001B1A99 /* CNLiveWebView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CNLiveWebView.m; sourceTree = "<group>"; };
@@ -165,6 +168,8 @@ @@ -165,6 +168,8 @@
165 6003F5A6195388D20070C39A /* CNLIVEViewController.m */, 168 6003F5A6195388D20070C39A /* CNLIVEViewController.m */,
166 08ADA66023A381E100072772 /* CNLiveBaseViewController.h */, 169 08ADA66023A381E100072772 /* CNLiveBaseViewController.h */,
167 08ADA66123A381E100072772 /* CNLiveBaseViewController.m */, 170 08ADA66123A381E100072772 /* CNLiveBaseViewController.m */,
  171 + 08827AFC23A8B4AC00EBF18F /* UIViewController+NavigationBarHidden.h */,
  172 + 08827AFD23A8B4AC00EBF18F /* UIViewController+NavigationBarHidden.m */,
168 08CA954E23A47090001B1A99 /* CNLiveBaseNavigationController.h */, 173 08CA954E23A47090001B1A99 /* CNLiveBaseNavigationController.h */,
169 08CA954F23A47090001B1A99 /* CNLiveBaseNavigationController.m */, 174 08CA954F23A47090001B1A99 /* CNLiveBaseNavigationController.m */,
170 08CA954C23A4609F001B1A99 /* CNLiveWebView.h */, 175 08CA954C23A4609F001B1A99 /* CNLiveWebView.h */,
@@ -456,6 +461,7 @@ @@ -456,6 +461,7 @@
456 08ADA66223A381E100072772 /* CNLiveBaseViewController.m in Sources */, 461 08ADA66223A381E100072772 /* CNLiveBaseViewController.m in Sources */,
457 08CA955923A4B492001B1A99 /* CNLiveBaseWebViewController.m in Sources */, 462 08CA955923A4B492001B1A99 /* CNLiveBaseWebViewController.m in Sources */,
458 6003F59E195388D20070C39A /* CNLIVEAppDelegate.m in Sources */, 463 6003F59E195388D20070C39A /* CNLIVEAppDelegate.m in Sources */,
  464 + 08827AFE23A8B4AC00EBF18F /* UIViewController+NavigationBarHidden.m in Sources */,
459 6003F5A7195388D20070C39A /* CNLIVEViewController.m in Sources */, 465 6003F5A7195388D20070C39A /* CNLIVEViewController.m in Sources */,
460 08CA955C23A4B552001B1A99 /* CNLiveInteractionWebController.m in Sources */, 466 08CA955C23A4B552001B1A99 /* CNLiveInteractionWebController.m in Sources */,
461 6003F59A195388D20070C39A /* main.m in Sources */, 467 6003F59A195388D20070C39A /* main.m in Sources */,
Example/CNLiveBalanceModule/CNLiveBaseNavigationController.h
@@ -10,7 +10,7 @@ @@ -10,7 +10,7 @@
10 10
11 NS_ASSUME_NONNULL_BEGIN 11 NS_ASSUME_NONNULL_BEGIN
12 12
13 -@interface CNLiveBaseNavigationController : UINavigationController 13 +@interface CNLiveBaseNavigationController : UINavigationController<UINavigationControllerDelegate>
14 14
15 @end 15 @end
16 16
Example/CNLiveBalanceModule/CNLiveBaseNavigationController.m
@@ -7,16 +7,81 @@ @@ -7,16 +7,81 @@
7 // 7 //
8 8
9 #import "CNLiveBaseNavigationController.h" 9 #import "CNLiveBaseNavigationController.h"
  10 +#import "UIViewController+NavigationBarHidden.h"
  11 +#import "CNLiveCategory.h"
10 12
11 -@interface CNLiveBaseNavigationController () 13 +@interface CNLiveBaseNavigationController ()<UIGestureRecognizerDelegate>
12 14
13 @end 15 @end
14 16
15 @implementation CNLiveBaseNavigationController 17 @implementation CNLiveBaseNavigationController
  18 +#pragma mark - 生命周期
  19 +- (void)viewDidAppear:(BOOL)animated {
  20 + __weak typeof(self) weakSelf = self;
  21 + self.navigationController.interactivePopGestureRecognizer.delegate = weakSelf;
  22 +}
16 23
17 - (void)viewDidLoad { 24 - (void)viewDidLoad {
18 [super viewDidLoad]; 25 [super viewDidLoad];
19 // Do any additional setup after loading the view. 26 // Do any additional setup after loading the view.
  27 + self.delegate = self;
  28 +}
  29 +
  30 +#pragma mark - 重写push方法
  31 +//重写push方法 push的控制器隐藏tabbar
  32 +- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated {
  33 + // 隐藏tabbar
  34 + if (self.viewControllers.count > 0) {
  35 + viewController.hidesBottomBarWhenPushed = YES;
  36 + }
  37 + //1.添加后退按钮
  38 + [self addBackButton:viewController];
  39 + [super pushViewController:viewController animated:animated];
  40 +}
  41 +
  42 +//2 自定义后退按钮
  43 +- (void)addBackButton:(UIViewController *)viewController {
  44 + //开启手势后退
  45 + self.interactivePopGestureRecognizer.delegate = (id)self;
  46 + //开启手势滑动后退
  47 + if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
  48 + self.interactivePopGestureRecognizer.enabled = YES;
  49 + }
  50 +
  51 + UIImage *image = [self getImageWithImageName:@"cnlive_back_black_b" bundleName:@"CNLiveBaseClass" targetClass:[self class]];
  52 + UIImage *originalImage = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
  53 +
  54 + //设置导航栏返回按钮
  55 + UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
  56 + btn.frame = CGRectMake(0, 0, 44, 44);
  57 + [btn setImage:originalImage forState:UIControlStateNormal];
  58 + [btn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
  59 + [btn addTarget:self action:@selector(goBack) forControlEvents:UIControlEventTouchUpInside];
  60 + UIBarButtonItem *leftItem = [[UIBarButtonItem alloc]initWithCustomView:btn];
  61 + viewController.navigationItem.leftBarButtonItem = leftItem;
  62 +}
  63 +
  64 +//点击后退的时候执行的方法
  65 +- (void)goBack {
  66 + [self popViewControllerAnimated:YES];
  67 +}
  68 +
  69 +#pragma mark - UINavigationControllerDelegate
  70 +- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
  71 + if (viewController.navigationBarHidden != self.navigationBarHidden) {
  72 + [self setNavigationBarHidden:viewController.navigationBarHidden animated:animated];
  73 + }
  74 +}
  75 +
  76 +#pragma mark - UIGestureRecognizerDelegate
  77 +- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
  78 + // 注意:只有非根控制器才有滑动返回功能,根控制器没有。
  79 + // 判断导航控制器是否只有一个子控制器,如果只有一个子控制器,肯定是根控制器
  80 + if (self.childViewControllers.count == 1) {
  81 + // 表示用户在根控制器界面,就不需要触发滑动手势,
  82 + return NO;
  83 + }
  84 + return YES;
20 } 85 }
21 86
22 /* 87 /*
Example/CNLiveBalanceModule/CNLiveBaseViewController.h
@@ -14,6 +14,9 @@ NS_ASSUME_NONNULL_BEGIN @@ -14,6 +14,9 @@ NS_ASSUME_NONNULL_BEGIN
14 // 是否隐藏导航栏 14 // 是否隐藏导航栏
15 @property (nonatomic, assign) BOOL navigationHidden; 15 @property (nonatomic, assign) BOOL navigationHidden;
16 16
  17 +// 是否开启侧滑返回手势
  18 +@property (nonatomic, assign) BOOL interactive;
  19 +
17 // 子类重写添加子视图方法 20 // 子类重写添加子视图方法
18 - (void)createSubViews; 21 - (void)createSubViews;
19 22
Example/CNLiveBalanceModule/CNLiveBaseViewController.m
@@ -21,6 +21,16 @@ @@ -21,6 +21,16 @@
21 self.navigationController.navigationBarHidden = YES; 21 self.navigationController.navigationBarHidden = YES;
22 } 22 }
23 23
  24 +- (void)viewDidAppear:(BOOL)animated {
  25 + [super viewDidAppear:animated];
  26 + // 禁止页面左侧滑动返回,注意,如果仅仅需要禁止此单个页面返回,还需要在viewWillDisapper下开放侧滑权限
  27 + // 禁用返回手势
  28 + if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
  29 + self.navigationController.interactivePopGestureRecognizer.enabled = self.interactive;
  30 + }
  31 +
  32 +}
  33 +
24 - (void)viewDidLoad { 34 - (void)viewDidLoad {
25 [super viewDidLoad]; 35 [super viewDidLoad];
26 // Do any additional setup after loading the view. 36 // Do any additional setup after loading the view.
Example/CNLiveBalanceModule/UIViewController+NavigationBarHidden.h 0 → 100644
  1 +//
  2 +// UIViewController+NavigationBarHidden.m
  3 +// CNLiveBaseClass
  4 +//
  5 +// Created by CNLive-zxw on 2019/12/13.
  6 +// Copyright © 2019 153993236@qq.com. All rights reserved.
  7 +//
  8 +
  9 +#import <UIKit/UIKit.h>
  10 +
  11 +NS_ASSUME_NONNULL_BEGIN
  12 +
  13 +@interface UIViewController (NavigationBarHidden)
  14 +// 是否隐藏导航栏。默认NO。
  15 +@property (nonatomic , assign) BOOL navigationBarHidden;
  16 +
  17 +@end
  18 +
  19 +NS_ASSUME_NONNULL_END
Example/CNLiveBalanceModule/UIViewController+NavigationBarHidden.m 0 → 100644
  1 +//
  2 +// UIViewController+NavigationBarHidden.m
  3 +// CNLiveBaseClass
  4 +//
  5 +// Created by CNLive-zxw on 2019/12/13.
  6 +// Copyright © 2019 153993236@qq.com. All rights reserved.
  7 +//
  8 +
  9 +#import "UIViewController+NavigationBarHidden.h"
  10 +#import <objc/runtime.h>
  11 +
  12 +@implementation UIViewController (NavigationBarHidden)
  13 +- (BOOL)navigationBarHidden{
  14 + return [objc_getAssociatedObject(self, @selector(navigationBarHidden)) boolValue];
  15 +}
  16 +
  17 +- (void)setNavigationBarHidden:(BOOL)navigationBarHidden{
  18 + objc_setAssociatedObject(self, @selector(navigationBarHidden), @(navigationBarHidden), OBJC_ASSOCIATION_ASSIGN);
  19 +}
  20 +
  21 +@end