解决ios流海屏问题

这里处理留海屏的方式是吧整个窗口缩小,然后调整位置

1.在导出的xcode工程中找到UnityAppController.mm,引用头文件#import

2.添加获取设备机型的方法

  -(NSString*)getDeviceVersion

  {

    struct utsname systemInfo;

    uname(&systemInfo);

    NSString *deviceVersion = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];

    return deviceVersion;

  }

3.找到didFinishLaunchingWithOptions方法中的_window =[[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];替换成以下代码

  NSString *deviceVersion = [self getDeviceVersion];

if ([deviceVersion isEqualToString:@"iPhone10, 3"] || [deviceVersion isEqualToString:@"iPhone10, 6"] ||

        [deviceVersion isEqualToString:@"iPhone11, 8"] ||

        [deviceVersion isEqualToString:@"iPhone11, 2"] ||

        [deviceVersion isEqualToString:@"iPhone11, 6"] )

{

CGRect winsize = [UIScreen mainScreen].bounds;

        UIInterfaceOrientation sataus=[UIApplication sharedApplication].statusBarOrientation;

if(sataus == UIInterfaceOrientationLandscapeLeft){

winsize.size.width -=32;

winsize.origin.x = 0;

}else{winsize.size.width -=32;

winsize.origin.x = 32;

}

_window = [[UIWindow alloc] initWithFrame:winsize];

}else

{

_window =[[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];

}

如果是2017版本这样操作出现了问题可以查看  处理unity2017.4.30留海屏,窗体不能缩放问题

 

你可能感兴趣的:(IOS,Unity)