[IOS] iphoneX simple adaptation

The business interface has a tab bar. Since the screen height of the iPhone X is 812, there will be a gap between the tab bar and the layout. Just move the tab bar up and set the background to black to leave a black border underneath.

 

Judging iPhone X:

#define KIsiPhoneX ([UIScreen instancesRespondToSelector:@selector
(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1125, 2436), [[UIScreen mainScreen]
currentMode].size) : NO)

 

If it is an iPhone X, change the y point and draw the tab bar button of your code upwards:

if (KIsiPhoneX) {
        bottom_tab_bar_view = [[UIView alloc] initWithFrame:CGRectMake(0,
screenHeight - 83, screenWidth, 55)];
        
    }else{
        bottom_tab_bar_view = [[UIView alloc] initWithFrame:CGRectMake(0,
screenHeight - 55, screenWidth, 55)];
    }

Since my custom tab bar originally covered the native tab bar view of the system, the layer of the native tab bar view will be displayed after drawing upwards. Generally, there are two ways to deal with it:

1. Change the background color of the tab bar view to black, leaving a black border below:

self.tabBar.barTintColor = [UIColor blackColor];
// [[UITabBar appearance] setBarTintColor:[UIColor blackColor]];//The second way of writing, choose one
    [UITabBar appearance].translucent = NO;

 

2. The tab bar view of the system is hidden, and the background color of the controller is displayed (can be set to black):

[self.tabBar setHidden:YES];

 But there is a problem here. In the ios mechanism, all views are stretched to the full size of the screen. In fact, the navigation bar and tab bar are ignored in the display, that is to say, the navigation bar and tab bar will not block the view in the storyboard that is full of page size. . But I hide the tab bar here, which causes the whole page to move down, and the part that can be displayed is blocked by my custom tab bar. In this case, you can only add a height constraint from the bottom tab bar to each occluded controller to make the page go up again.

 

The display effect of the two methods is basically the same. However, since the second method makes the entire page upward, the original UI can be basically maintained, especially the zoom ratio of the picture. The first method is relatively simple, but due to the larger screen ratio of the iPhone X, the picture will be stretched in some places.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326015890&siteId=291194637