JLChen
2021-05-17 a722e767f98042d5ef6259d2dde7854c925e4167
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
//
//  Copyright © 2018年 Anson. All rights reserved.
//
 
 
#import <LCBaseModule/DHContainerVC.h>
#import <LCBaseModule/DHBaseViewController.h>
#import <LCBaseModule/UIColor+LeChange.h>
#import <Masonry/Masonry.h>
 
@interface DHContainerVC ()<UIGestureRecognizerDelegate>
 
@end
 
@implementation DHContainerVC
 
#pragma mark - 初始化 及 析构
- (instancetype)init
{
    if (self = [super init]) {
    }
    return self;
}
 
- (void)dealloc
{
    NSLog(@"DHContainerVC dealloc");
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}
 
#pragma mark - state
 
#pragma mark - View生命周期
- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationController.navigationBarHidden = YES;
    self.edgesForExtendedLayout = UIRectEdgeAll;
    self.view.backgroundColor = [UIColor dhcolor_c43];
 
    if (self.contentViewController && self.contentViewController.navBar) {
         [self.view addSubview:self.contentViewController.navBar];
    }
   
    self.view.clipsToBounds = YES;
    
    UINavigationBar *bar = self.contentViewController.navBar;
    if ([bar isKindOfClass:[UINavigationBar class]]) {
        bar.titleTextAttributes = @{NSForegroundColorAttributeName : [UIColor dhcolor_c2]};
    }
    [bar mas_makeConstraints:^(MASConstraintMaker *make) {
        CGRect statusRect = [[UIApplication sharedApplication] statusBarFrame];
        make.top.equalTo(self.view).offset(self.contentViewController.navigationBarHidden ? 0 : statusRect.size.height);
        make.left.equalTo(self.view).offset(-10);
        make.right.equalTo(self.view).offset(10);
        make.height.mas_equalTo(self.contentViewController.navigationBarHidden ? 0 : 44.0);
    }];
    
    [bar layoutIfNeeded];
 
    // 这里会触发self.contentViewControlle 的viewDidLoad
    self.contentViewController.view.clipsToBounds = YES;
    [self.view addSubview:self.contentViewController.view];
    [self.contentViewController.view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentViewController.navBar.mas_bottom);
        make.left.equalTo(self.view);
        make.right.equalTo(self.view);
        make.bottom.equalTo(self.view);
    }];
}
 
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden = YES;
}
 
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}
 
#pragma mark - setter getter
- (void)setContentViewController:(UIViewController<IDHContentVC> *)contentViewController
{
    _contentViewController = contentViewController;
    [self addChildViewController:_contentViewController];
}
 
 
#pragma mark - Rotate
 
- (BOOL)shouldAutorotate
{
    if ([_contentViewController respondsToSelector:@selector(shouldAutorotate)]) {
        return [_contentViewController shouldAutorotate];
    }
    
    return NO;
}
 
- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
    if ([_contentViewController respondsToSelector:@selector(supportedInterfaceOrientations)]) {
        return [_contentViewController supportedInterfaceOrientations];
    }
    
    return UIInterfaceOrientationMaskPortrait;
}
 
//全链路埋点
- (NSString *)sensorsdata_screenName {
    
    return NSStringFromClass([self.contentViewController class]);
}
 
@end