iPhoneX的适配没问题 但是xs max显示tabbar就混乱,如图:
原因就是tabbar高度获取都是49 但是系统给留了34的高度放在最下面不让你用,用来显示你的tabbar的高度就剩下了49-34=15了。所以都挤在一起特别混乱,解决办法就是在xsmax的机型上人为改动tabbar的高度即可。
我的baseviewcontroller是basetabbarcontroller。所以在tabbarcontroller的.m里加上这个方法:
//记得引入头文件,用来判断手机型号的
#import <sys/sysctl.h>
#import <sys/utsname.h>
- (void)viewWillLayoutSubviews {
if (!self.tabBarHeight) {
return;
}
//模拟器的获取设备号的方法
NSString *model = NSProcessInfo.processInfo.environment[@"SIMULATOR_MODEL_IDENTIFIER"];
if ([[self machineName1] isEqualToString:@"iPhone11,4"] || [[self machineName1] isEqualToString:@"iPhone11,6"] || [model isEqualToString:@"iPhone11,4"] || [model isEqualToString:@"iPhone11,6"]) {
self.tabBarHeight = 83;
}
//因为xsmax在哪个方法里获取都是49 所以我们要人为改变高度变为83;其他机型暂时不用处理,获取的都是正确的高度
self.tabBar.frame = ({
CGRect frame = self.tabBar.frame;
CGFloat tabBarHeight = self.tabBarHeight;
frame.size.height = tabBarHeight;
frame.origin.y = self.view.frame.size.height - tabBarHeight;
frame;
});
}
// 获取 device model/machine name 的方法一
-(NSString *)machineName1 {
size_t size;
sysctlbyname("hw.machine", NULL, &size, NULL, 0);
char *machine = (char *)malloc(size);
if (machine == NULL) {
return nil;
}
sysctlbyname("hw.machine", machine, &size, NULL, 0);
NSString *platform = [NSString stringWithCString:machine encoding:NSUTF8StringEncoding];
free(machine);
return platform;
}
其他文章请查看个人博客:http://zhangqq166.cn/