CNLiveBaseViewController.m
2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
//
// CNLiveBaseViewController.m
// CNLiveBaseClass
//
// Created by CNLive-zxw on 2019/12/13.
// Copyright © 2019 153993236@qq.com. All rights reserved.
//
#import "CNLiveBaseViewController.h"
#import "CNLiveNavigationBar.h"
@interface CNLiveBaseViewController ()
@property (nonatomic, strong) CNLiveNavigationBar *navigationBar;
@end
@implementation CNLiveBaseViewController
#pragma mark - 生命周期
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
self.navigationController.navigationBarHidden = YES;
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
// 禁止页面左侧滑动返回,注意,如果仅仅需要禁止此单个页面返回,还需要在viewWillDisapper下开放侧滑权限
// 禁用返回手势
if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
self.navigationController.interactivePopGestureRecognizer.enabled = self.interactive;
}
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor whiteColor];
self.automaticallyAdjustsScrollViewInsets = NO;
[self createSubViews];
}
#pragma mark - UI
- (void)createSubViews{
[self.view addSubview:self.navigationBar];
}
#pragma mark - Setter方法
- (void)setTitle:(NSString *)title{
[super setTitle:title];
self.navigationBar.title.text = title;
}
- (void)setNavigationHidden:(BOOL)navigationHidden{
_navigationHidden = navigationHidden;
_navigationBar.hidden = navigationHidden;
}
/*
#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.
}
*/
#pragma mark - 响应方法
- (void)goBack {
if (self.presentingViewController != nil) {
[self dismissViewControllerAnimated:YES completion:nil];
}
else {
[self.navigationController popViewControllerAnimated:YES];
}
}
#pragma mark - 懒加载
- (CNLiveNavigationBar *)navigationBar {
if (!_navigationBar) {
_navigationBar = [CNLiveNavigationBar navigationBar];
_navigationBar.title.text = self.title;
__weak typeof(self) weakSelf = self;
_navigationBar.onClickLeftButton = ^{
__strong typeof(weakSelf) strongSelf = weakSelf;
if(!strongSelf) return ;
[strongSelf goBack];
};
}
return _navigationBar;
}
@end