Commit 0a4fc63448eda7f124a8c90cf583c596baddc73f

Authored by liushiyu
1 parent 365bef34

去除QMUI依赖

CNLiveCustomControl/Classes/NavigationBar/CNLiveNavigationBar.m
... ... @@ -7,9 +7,16 @@
7 7 //
8 8  
9 9 #import "CNLiveNavigationBar.h"
10   -#import "QMUIKit.h"
11 10 #import "CNLiveCategory.h"
12 11  
  12 +
  13 +/// 状态栏高度(来电等情况下,状态栏高度会发生变化,所以应该实时计算,iOS 13 起,来电等情况下状态栏高度不会改变)
  14 +#define StatusBarHeight_Custom (UIApplication.sharedApplication.statusBarHidden ? 0 : UIApplication.sharedApplication.statusBarFrame.size.height)
  15 +
  16 +#define NavigationContentTop_Custom (StatusBarHeight_Custom + 44)
  17 +
  18 +/// 屏幕宽度,会根据横竖屏的变化而变化
  19 +#define SCREEN_WIDTH_Custom ([[UIScreen mainScreen] bounds].size.width)
13 20 @interface CNLiveNavigationBar ()
14 21 @property (nonatomic, strong) UIView *navView;
15 22 @property (nonatomic, strong) UIView *line;
... ... @@ -20,7 +27,7 @@
20 27 static const NSInteger margin = 15;
21 28 #pragma mark - 初始化
22 29 + (instancetype)navigationBar {
23   - CNLiveNavigationBar *navigationBar = [[self alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, NavigationContentTop)];
  30 + CNLiveNavigationBar *navigationBar = [[self alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH_Custom, NavigationContentTop_Custom)];
24 31 return navigationBar;
25 32 }
26 33  
... ... @@ -120,7 +127,7 @@ static const NSInteger margin = 15;
120 127 #pragma mark - 懒加载
121 128 - (UIView *)navView {
122 129 if (!_navView) {
123   - _navView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, NavigationContentTop)];
  130 + _navView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH_Custom, NavigationContentTop_Custom)];
124 131 _navView.backgroundColor = [UIColor clearColor];
125 132 }
126 133 return _navView;
... ... @@ -130,7 +137,7 @@ static const NSInteger margin = 15;
130 137 if (!_left) {
131 138 _left= [UIButton buttonWithType:UIButtonTypeCustom];
132 139 _left.adjustsImageWhenHighlighted = NO;
133   - _left.frame = CGRectMake(margin, StatusBarHeight, NavigationBarHeight, NavigationBarHeight);
  140 + _left.frame = CGRectMake(margin, StatusBarHeight_Custom, 44, 44);
134 141 UIImage *image = [self getImageWithImageName:@"NavigationBar.bundle/cnlive_back_black_b" bundleName:@"CNLiveCustomControl" targetClass:[self class]];
135 142 [_left setImage:[image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
136 143 _left.titleLabel.font = [UIFont systemFontOfSize:15];
... ... @@ -143,7 +150,7 @@ static const NSInteger margin = 15;
143 150  
144 151 - (UILabel *)title {
145 152 if (!_title) {
146   - _title = [[UILabel alloc] initWithFrame:CGRectMake(margin+NavigationBarHeight, StatusBarHeight, SCREEN_WIDTH-2*(margin+NavigationBarHeight), NavigationBarHeight)];
  153 + _title = [[UILabel alloc] initWithFrame:CGRectMake(margin+44, StatusBarHeight_Custom, SCREEN_WIDTH_Custom-2*(margin+44), 44)];
147 154 _title.font = [UIFont systemFontOfSize:18];
148 155 _title.textColor = [UIColor blackColor];
149 156 _title.textAlignment = NSTextAlignmentCenter;
... ... @@ -154,7 +161,7 @@ static const NSInteger margin = 15;
154 161 - (UIButton *)right {
155 162 if (!_right) {
156 163 _right = [UIButton buttonWithType:UIButtonTypeCustom];
157   - _right.frame = CGRectMake(SCREEN_WIDTH-NavigationBarHeight-margin, StatusBarHeight, NavigationBarHeight, NavigationBarHeight);
  164 + _right.frame = CGRectMake(SCREEN_WIDTH_Custom-44-margin, StatusBarHeight_Custom, 44, 44);
158 165 [_right setContentHorizontalAlignment:UIControlContentHorizontalAlignmentRight];
159 166 _right.adjustsImageWhenHighlighted = NO;
160 167 _right.titleLabel.font = [UIFont systemFontOfSize:15];
... ... @@ -167,7 +174,7 @@ static const NSInteger margin = 15;
167 174  
168 175 - (UIView *)line {
169 176 if (!_line) {
170   - _line = [[UIView alloc] initWithFrame:CGRectMake(0, NavigationContentTop-0.5, SCREEN_WIDTH, 0.5)];
  177 + _line = [[UIView alloc] initWithFrame:CGRectMake(0, NavigationContentTop_Custom-0.5, SCREEN_WIDTH_Custom, 0.5)];
171 178 _line.backgroundColor = [UIColor colorWithRed:(CGFloat)(218.0/255.0) green:(CGFloat)(218.0/255.0) blue:(CGFloat)(218.0/255.0) alpha:1.0];
172 179 }
173 180 return _line;
... ...