Skip to content

Commit c38b26a

Browse files
committed
[add]iphonex适配
1 parent d3908fb commit c38b26a

3 files changed

Lines changed: 28 additions & 21 deletions

File tree

NetworkEye/NetworkEye/NEHTTPEyeDetailViewController.m

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,42 +23,44 @@ - (void)viewDidLoad {
2323
[super viewDidLoad];
2424
// Do any additional setup after loading the view.
2525

26+
BOOL isiPhoneX = (([[UIScreen mainScreen] bounds].size.width == 375.f && [[UIScreen mainScreen] bounds].size.height == 812.f) || ([[UIScreen mainScreen] bounds].size.height == 375.f && [[UIScreen mainScreen] bounds].size.width == 812.f));
27+
2628
if ([[[UIDevice currentDevice]systemVersion] floatValue] >= 7.0) {
2729
self.edgesForExtendedLayout = UIRectEdgeBottom | UIRectEdgeLeft | UIRectEdgeRight;
2830

2931
}
3032
self.automaticallyAdjustsScrollViewInsets=NO;
3133
self.view.backgroundColor=[UIColor whiteColor];
3234

33-
UINavigationBar *bar=[[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, [[UIScreen mainScreen] bounds].size.width, 64)];
35+
UIView *bar=[[UIView alloc] initWithFrame:CGRectMake(0, 0, [[UIScreen mainScreen] bounds].size.width, 64+(isiPhoneX?24:0))];
3436
[self.view addSubview:bar];
35-
bar.barTintColor=[UIColor colorWithRed:0.24f green:0.51f blue:0.78f alpha:1.00f];
37+
bar.backgroundColor=[UIColor colorWithRed:0.24f green:0.51f blue:0.78f alpha:1.00f];
3638

3739
UIButton *backBt=[UIButton buttonWithType:UIButtonTypeCustom];
38-
backBt.frame=CGRectMake(10, 27, 40, 30);
40+
backBt.frame=CGRectMake(10, 27+(isiPhoneX?24:0), 40, 30);
3941
[backBt setTitle:@"back" forState:UIControlStateNormal];
4042
backBt.titleLabel.font=[UIFont systemFontOfSize:15];
4143
[backBt setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
4244
[backBt addTarget:self action:@selector(backBtAction) forControlEvents:UIControlEventTouchUpInside];
4345
[bar addSubview:backBt];
4446

4547
UIButton *mapBt=[UIButton buttonWithType:UIButtonTypeCustom];
46-
mapBt.frame=CGRectMake([[UIScreen mainScreen] bounds].size.width-60, 27, 50, 30);
48+
mapBt.frame=CGRectMake([[UIScreen mainScreen] bounds].size.width-60, 27+(isiPhoneX?24:0), 50, 30);
4749
[mapBt setTitle:@"map" forState:UIControlStateNormal];
4850
mapBt.titleLabel.font=[UIFont systemFontOfSize:13];
4951
[mapBt setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
5052
[mapBt addTarget:self action:@selector(rightAction) forControlEvents:UIControlEventTouchUpInside];
5153
[bar addSubview:mapBt];
5254

53-
UILabel *titleText = [[UILabel alloc] initWithFrame: CGRectMake(([[UIScreen mainScreen] bounds].size.width-230)/2, 20, 230, 44)];
55+
UILabel *titleText = [[UILabel alloc] initWithFrame: CGRectMake(([[UIScreen mainScreen] bounds].size.width-230)/2, 20+(isiPhoneX?24:0), 230, 44)];
5456
titleText.backgroundColor = [UIColor clearColor];
5557
titleText.textColor=[UIColor whiteColor];
5658
[titleText setFont:[UIFont systemFontOfSize:13.0]];
5759
titleText.textAlignment=NSTextAlignmentCenter;
5860
[bar addSubview:titleText];
5961
titleText.text=_model.requestURLString;
6062

61-
mainTextView=[[UITextView alloc] initWithFrame:CGRectMake(0, 64, [[UIScreen mainScreen] bounds].size.width, [[UIScreen mainScreen] bounds].size.height-64)];
63+
mainTextView=[[UITextView alloc] initWithFrame:CGRectMake(0, 64+(isiPhoneX?24:0), [[UIScreen mainScreen] bounds].size.width, [[UIScreen mainScreen] bounds].size.height-64-(isiPhoneX?24:0))];
6264
[self.view addSubview:mainTextView];
6365
mainTextView.editable=NO;
6466

NetworkEye/NetworkEye/NEHTTPEyeSettingsViewController.m

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,34 +21,37 @@ @implementation NEHTTPEyeSettingsViewController
2121
- (void)viewDidLoad {
2222
[super viewDidLoad];
2323
// Do any additional setup after loading the view.
24+
25+
BOOL isiPhoneX = (([[UIScreen mainScreen] bounds].size.width == 375.f && [[UIScreen mainScreen] bounds].size.height == 812.f) || ([[UIScreen mainScreen] bounds].size.height == 375.f && [[UIScreen mainScreen] bounds].size.width == 812.f));
26+
2427
if ([[[UIDevice currentDevice]systemVersion] floatValue] >= 7.0) {
2528
self.edgesForExtendedLayout = UIRectEdgeBottom | UIRectEdgeLeft | UIRectEdgeRight;
2629

2730
}
2831
self.automaticallyAdjustsScrollViewInsets=NO;
2932
self.view.backgroundColor=[UIColor whiteColor];
3033

31-
UINavigationBar *bar=[[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, [[UIScreen mainScreen] bounds].size.width, 64)];
34+
UIView *bar=[[UIView alloc] initWithFrame:CGRectMake(0, 0, [[UIScreen mainScreen] bounds].size.width, 64+(isiPhoneX?24:0))];
3235
[self.view addSubview:bar];
33-
bar.barTintColor=[UIColor colorWithRed:0.24f green:0.51f blue:0.78f alpha:1.00f];
36+
bar.backgroundColor=[UIColor colorWithRed:0.24f green:0.51f blue:0.78f alpha:1.00f];
3437

3538
UIButton *backBt=[UIButton buttonWithType:UIButtonTypeCustom];
36-
backBt.frame=CGRectMake(10, 27, 40, 30);
39+
backBt.frame=CGRectMake(10, 27+(isiPhoneX?24:0), 40, 30);
3740
[backBt setTitle:@"back" forState:UIControlStateNormal];
3841
backBt.titleLabel.font=[UIFont systemFontOfSize:15];
3942
[backBt setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
4043
[backBt addTarget:self action:@selector(backBtAction) forControlEvents:UIControlEventTouchUpInside];
4144
[bar addSubview:backBt];
4245

43-
UILabel *titleText = [[UILabel alloc] initWithFrame: CGRectMake(([[UIScreen mainScreen] bounds].size.width-230)/2, 20, 230, 44)];
46+
UILabel *titleText = [[UILabel alloc] initWithFrame: CGRectMake(([[UIScreen mainScreen] bounds].size.width-230)/2, 20+(isiPhoneX?24:0), 230, 44)];
4447
titleText.backgroundColor = [UIColor clearColor];
4548
titleText.textColor=[UIColor whiteColor];
4649
[titleText setFont:[UIFont systemFontOfSize:15.0]];
4750
titleText.textAlignment=NSTextAlignmentCenter;
4851
[bar addSubview:titleText];
4952
titleText.text=@"settings";
5053

51-
mainTableView=[[UITableView alloc] initWithFrame:CGRectMake(0, 64, [[UIScreen mainScreen] bounds].size.width, [[UIScreen mainScreen] bounds].size.height-64) style:UITableViewStyleGrouped];
54+
mainTableView=[[UITableView alloc] initWithFrame:CGRectMake(0, 64+(isiPhoneX?24:0), [[UIScreen mainScreen] bounds].size.width, [[UIScreen mainScreen] bounds].size.height-64-(isiPhoneX?24:0)) style:UITableViewStyleGrouped];
5255
[self.view addSubview:mainTableView];
5356
mainTableView.dataSource=self;
5457
mainTableView.delegate=self;

NetworkEye/NetworkEye/NEHTTPEyeViewController.m

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ @interface NEHTTPEyeViewController ()<UITableViewDataSource,UITableViewDelegate,
1818
UISearchBar *mySearchBar;
1919
UISearchDisplayController *mySearchDisplayController;
2020
NSArray *filterHTTPRequests;
21+
BOOL isiPhoneX;
2122
}
2223

2324
@end
@@ -28,11 +29,12 @@ - (void)viewDidLoad {
2829
[super viewDidLoad];
2930
// Do any additional setup after loading the view.
3031

31-
32+
isiPhoneX = (([[UIScreen mainScreen] bounds].size.width == 375.f && [[UIScreen mainScreen] bounds].size.height == 812.f) || ([[UIScreen mainScreen] bounds].size.height == 375.f && [[UIScreen mainScreen] bounds].size.width == 812.f));
33+
3234
self.automaticallyAdjustsScrollViewInsets=NO;
3335
self.view.backgroundColor=[UIColor whiteColor];
3436

35-
mainTableView=[[UITableView alloc] initWithFrame:CGRectMake(0, 0, [[UIScreen mainScreen] bounds].size.width, [[UIScreen mainScreen] bounds].size.height-64) style:UITableViewStylePlain];
37+
mainTableView=[[UITableView alloc] initWithFrame:CGRectMake(0, 0, [[UIScreen mainScreen] bounds].size.width, [[UIScreen mainScreen] bounds].size.height-64-(isiPhoneX?24:0)) style:UITableViewStylePlain];
3638
[self.view addSubview:mainTableView];
3739

3840
double flowCount=[[[NSUserDefaults standardUserDefaults] objectForKey:@"flowCount"] doubleValue];
@@ -59,35 +61,35 @@ - (void)viewDidLoad {
5961
NSMutableAttributedString *attrText = [[NSMutableAttributedString alloc] init];
6062
[attrText appendAttributedString:titleString];
6163
[attrText appendAttributedString:flowCountString];
62-
UILabel *titleText = [[UILabel alloc] initWithFrame: CGRectMake(([[UIScreen mainScreen] bounds].size.width-120)/2, 20, 120, 44)];
64+
UILabel *titleText = [[UILabel alloc] initWithFrame: CGRectMake(([[UIScreen mainScreen] bounds].size.width-120)/2, 20+(isiPhoneX?24:0), 120, 44)];
6365
titleText.backgroundColor = [UIColor clearColor];
6466
titleText.textColor=[UIColor whiteColor];
6567
titleText.textAlignment=NSTextAlignmentCenter;
6668
titleText.numberOfLines=0;
6769
titleText.attributedText=attrText;
6870

6971
if ([self.navigationController viewControllers].count<1) {
70-
UINavigationBar *bar=[[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, [[UIScreen mainScreen] bounds].size.width, 64)];
72+
UIView *bar=[[UIView alloc] initWithFrame:CGRectMake(0, 0, [[UIScreen mainScreen] bounds].size.width, 64+(isiPhoneX?24:0))];
7173
[self.view addSubview:bar];
72-
bar.barTintColor=[UIColor colorWithRed:0.24f green:0.51f blue:0.78f alpha:1.00f];
74+
bar.backgroundColor=[UIColor colorWithRed:0.24f green:0.51f blue:0.78f alpha:1.00f];
7375

7476

7577
UIButton *backBt=[UIButton buttonWithType:UIButtonTypeCustom];
76-
backBt.frame=CGRectMake(10, 27, 40, 30);
78+
backBt.frame=CGRectMake(10, 27+(isiPhoneX?24:0), 40, 30);
7779
[backBt setTitle:@"back" forState:UIControlStateNormal];
7880
backBt.titleLabel.font=[UIFont systemFontOfSize:15];
7981
[backBt setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
8082
[backBt addTarget:self action:@selector(backBtAction) forControlEvents:UIControlEventTouchUpInside];
8183
[bar addSubview:backBt];
8284

8385
UIButton *settingsBt=[UIButton buttonWithType:UIButtonTypeCustom];
84-
settingsBt.frame=CGRectMake([[UIScreen mainScreen] bounds].size.width-60, 27, 50, 30);
86+
settingsBt.frame=CGRectMake([[UIScreen mainScreen] bounds].size.width-60, 27+(isiPhoneX?24:0), 50, 30);
8587
[settingsBt setTitle:@"settings" forState:UIControlStateNormal];
8688
settingsBt.titleLabel.font=[UIFont systemFontOfSize:13];
8789
[settingsBt setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
8890
[settingsBt addTarget:self action:@selector(rightAction) forControlEvents:UIControlEventTouchUpInside];
8991
[bar addSubview:settingsBt];
90-
mainTableView.frame=CGRectMake(0, 64, [[UIScreen mainScreen] bounds].size.width, [[UIScreen mainScreen] bounds].size.height-64);
92+
mainTableView.frame=CGRectMake(0, 64+(isiPhoneX?24:0), [[UIScreen mainScreen] bounds].size.width, [[UIScreen mainScreen] bounds].size.height-64-(isiPhoneX?24:0));
9193
[bar addSubview:titleText];
9294
}else{
9395
titleText.frame=CGRectMake(([[UIScreen mainScreen] bounds].size.width-120)/2, 0, 120, 44);
@@ -200,7 +202,7 @@ - (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar {
200202
}
201203
//准备搜寻前,把上面调整的TableView调整回全屏幕的状态
202204
[UIView animateWithDuration:0.2 animations:^{
203-
mainTableView.frame = CGRectMake(0, 20, [[UIScreen mainScreen] bounds].size.width, [[UIScreen mainScreen] bounds].size.height-20);
205+
mainTableView.frame = CGRectMake(0, 20+(isiPhoneX?24:0), [[UIScreen mainScreen] bounds].size.width, [[UIScreen mainScreen] bounds].size.height-20-(isiPhoneX?24:0));
204206

205207
}];
206208

@@ -213,7 +215,7 @@ - (BOOL)searchBarShouldEndEditing:(UISearchBar *)searchBar {
213215
}
214216
if (searchBar.text.length<1) {
215217
[UIView animateWithDuration:0.2 animations:^{
216-
mainTableView.frame = CGRectMake(0, 64, [[UIScreen mainScreen] bounds].size.width, [[UIScreen mainScreen] bounds].size.height-64);
218+
mainTableView.frame = CGRectMake(0, 64+(isiPhoneX?24:0), [[UIScreen mainScreen] bounds].size.width, [[UIScreen mainScreen] bounds].size.height-64-(isiPhoneX?24:0));
217219
}];
218220
}
219221
//当按下search按钮后 后走这里,并且这之后按cancel按钮不会走这里;当没有按过search按钮,按cancel按钮会走这里

0 commit comments

Comments
 (0)