Commit 0a4fc63448eda7f124a8c90cf583c596baddc73f

Authored by liushiyu
1 parent 365bef34

去除QMUI依赖

CNLiveCustomControl/Classes/NavigationBar/CNLiveNavigationBar.m
@@ -7,9 +7,16 @@ @@ -7,9 +7,16 @@
7 // 7 //
8 8
9 #import "CNLiveNavigationBar.h" 9 #import "CNLiveNavigationBar.h"
10 -#import "QMUIKit.h"  
11 #import "CNLiveCategory.h" 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 @interface CNLiveNavigationBar () 20 @interface CNLiveNavigationBar ()
14 @property (nonatomic, strong) UIView *navView; 21 @property (nonatomic, strong) UIView *navView;
15 @property (nonatomic, strong) UIView *line; 22 @property (nonatomic, strong) UIView *line;
@@ -20,7 +27,7 @@ @@ -20,7 +27,7 @@
20 static const NSInteger margin = 15; 27 static const NSInteger margin = 15;
21 #pragma mark - 初始化 28 #pragma mark - 初始化
22 + (instancetype)navigationBar { 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 return navigationBar; 31 return navigationBar;
25 } 32 }
26 33
@@ -120,7 +127,7 @@ static const NSInteger margin = 15; @@ -120,7 +127,7 @@ static const NSInteger margin = 15;
120 #pragma mark - 懒加载 127 #pragma mark - 懒加载
121 - (UIView *)navView { 128 - (UIView *)navView {
122 if (!_navView) { 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 _navView.backgroundColor = [UIColor clearColor]; 131 _navView.backgroundColor = [UIColor clearColor];
125 } 132 }
126 return _navView; 133 return _navView;
@@ -130,7 +137,7 @@ static const NSInteger margin = 15; @@ -130,7 +137,7 @@ static const NSInteger margin = 15;
130 if (!_left) { 137 if (!_left) {
131 _left= [UIButton buttonWithType:UIButtonTypeCustom]; 138 _left= [UIButton buttonWithType:UIButtonTypeCustom];
132 _left.adjustsImageWhenHighlighted = NO; 139 _left.adjustsImageWhenHighlighted = NO;
133 - _left.frame = CGRectMake(margin, StatusBarHeight, NavigationBarHeight, NavigationBarHeight); 140 + _left.frame = CGRectMake(margin, StatusBarHeight_Custom, 44, 44);
134 UIImage *image = [self getImageWithImageName:@"NavigationBar.bundle/cnlive_back_black_b" bundleName:@"CNLiveCustomControl" targetClass:[self class]]; 141 UIImage *image = [self getImageWithImageName:@"NavigationBar.bundle/cnlive_back_black_b" bundleName:@"CNLiveCustomControl" targetClass:[self class]];
135 [_left setImage:[image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal]; 142 [_left setImage:[image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
136 _left.titleLabel.font = [UIFont systemFontOfSize:15]; 143 _left.titleLabel.font = [UIFont systemFontOfSize:15];
@@ -143,7 +150,7 @@ static const NSInteger margin = 15; @@ -143,7 +150,7 @@ static const NSInteger margin = 15;
143 150
144 - (UILabel *)title { 151 - (UILabel *)title {
145 if (!_title) { 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 _title.font = [UIFont systemFontOfSize:18]; 154 _title.font = [UIFont systemFontOfSize:18];
148 _title.textColor = [UIColor blackColor]; 155 _title.textColor = [UIColor blackColor];
149 _title.textAlignment = NSTextAlignmentCenter; 156 _title.textAlignment = NSTextAlignmentCenter;
@@ -154,7 +161,7 @@ static const NSInteger margin = 15; @@ -154,7 +161,7 @@ static const NSInteger margin = 15;
154 - (UIButton *)right { 161 - (UIButton *)right {
155 if (!_right) { 162 if (!_right) {
156 _right = [UIButton buttonWithType:UIButtonTypeCustom]; 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 [_right setContentHorizontalAlignment:UIControlContentHorizontalAlignmentRight]; 165 [_right setContentHorizontalAlignment:UIControlContentHorizontalAlignmentRight];
159 _right.adjustsImageWhenHighlighted = NO; 166 _right.adjustsImageWhenHighlighted = NO;
160 _right.titleLabel.font = [UIFont systemFontOfSize:15]; 167 _right.titleLabel.font = [UIFont systemFontOfSize:15];
@@ -167,7 +174,7 @@ static const NSInteger margin = 15; @@ -167,7 +174,7 @@ static const NSInteger margin = 15;
167 174
168 - (UIView *)line { 175 - (UIView *)line {
169 if (!_line) { 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 _line.backgroundColor = [UIColor colorWithRed:(CGFloat)(218.0/255.0) green:(CGFloat)(218.0/255.0) blue:(CGFloat)(218.0/255.0) alpha:1.0]; 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 return _line; 180 return _line;