Skip to content

Commit

Permalink
[add]iphonex适配
Browse files Browse the repository at this point in the history
  • Loading branch information
coderyi committed Oct 22, 2017
1 parent d3908fb commit c38b26a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 21 deletions.
14 changes: 8 additions & 6 deletions NetworkEye/NetworkEye/NEHTTPEyeDetailViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,42 +23,44 @@ - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.

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));

if ([[[UIDevice currentDevice]systemVersion] floatValue] >= 7.0) {
self.edgesForExtendedLayout = UIRectEdgeBottom | UIRectEdgeLeft | UIRectEdgeRight;

}
self.automaticallyAdjustsScrollViewInsets=NO;
self.view.backgroundColor=[UIColor whiteColor];

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

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

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

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

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

Expand Down
13 changes: 8 additions & 5 deletions NetworkEye/NetworkEye/NEHTTPEyeSettingsViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,34 +21,37 @@ @implementation NEHTTPEyeSettingsViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.

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));

if ([[[UIDevice currentDevice]systemVersion] floatValue] >= 7.0) {
self.edgesForExtendedLayout = UIRectEdgeBottom | UIRectEdgeLeft | UIRectEdgeRight;

}
self.automaticallyAdjustsScrollViewInsets=NO;
self.view.backgroundColor=[UIColor whiteColor];

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

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

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

mainTableView=[[UITableView alloc] initWithFrame:CGRectMake(0, 64, [[UIScreen mainScreen] bounds].size.width, [[UIScreen mainScreen] bounds].size.height-64) style:UITableViewStyleGrouped];
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];
[self.view addSubview:mainTableView];
mainTableView.dataSource=self;
mainTableView.delegate=self;
Expand Down
22 changes: 12 additions & 10 deletions NetworkEye/NetworkEye/NEHTTPEyeViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ @interface NEHTTPEyeViewController ()<UITableViewDataSource,UITableViewDelegate,
UISearchBar *mySearchBar;
UISearchDisplayController *mySearchDisplayController;
NSArray *filterHTTPRequests;
BOOL isiPhoneX;
}

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


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));

self.automaticallyAdjustsScrollViewInsets=NO;
self.view.backgroundColor=[UIColor whiteColor];

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

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

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


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

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

}];

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

0 comments on commit c38b26a

Please sign in to comment.