Query launch image at runtime

混江龙づ霸主 提交于 2019-11-29 07:32:30

No, you can't do this automagically. Querying the device rotation and selecting an image based on that is perfectly fine.

You really only need Portrait or Landscape in this situation though, assuming you are rotating your view properly.

As already stated by Joshua you cannot, as far as I am aware.

In case this might help someone else, if you are using asset catelogs the following code should provide the correct launch image for the current interface orientation.

NSString *suffix = nil;

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
    suffix = [[UIScreen mainScreen] bounds].size.height >= 568.0f ? @"-568h@2x" : @"@2x";
}
else {
    UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
    suffix = UIInterfaceOrientationIsPortrait(orientation) ? @"-Portrait" : @"-Landscape";
    suffix = [UIScreen mainScreen].scale == 2.0 ? [suffix stringByAppendingString:@"@2x~ipad"] : [suffix stringByAppendingString:@"~ipad"];
}

NSString *launchImageName = [NSString stringWithFormat:@"LaunchImage-700%@.png",suffix];
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!