react-native-navigation的迁移库

RNNSplashScreen.m 3.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #import "RNNSplashScreen.h"
  2. #import <UIKit/UIKit.h>
  3. @implementation RNNSplashScreen
  4. + (void)showOnWindow:(UIWindow *)window {
  5. CGRect screenBounds = [UIScreen mainScreen].bounds;
  6. CGFloat screenScale = [UIScreen mainScreen].scale;
  7. UIViewController *viewController = nil;
  8. NSString* launchStoryBoard = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"UILaunchStoryboardName"];
  9. if (launchStoryBoard != nil) {//load the splash from the storyboard that's defined in the info.plist as the LaunchScreen
  10. @try
  11. {
  12. UIStoryboard *storyboard = [UIStoryboard storyboardWithName:launchStoryBoard bundle:nil];
  13. viewController = [storyboard instantiateInitialViewController];
  14. }
  15. @catch(NSException *e)
  16. {
  17. UIView *splashView = [[NSBundle mainBundle] loadNibNamed:launchStoryBoard owner:self options:nil][0];
  18. if (splashView != nil)
  19. {
  20. splashView.frame = CGRectMake(0, 0, screenBounds.size.width, screenBounds.size.height);
  21. viewController = [[RNNSplashScreen alloc] init];
  22. viewController.view = splashView;
  23. }
  24. }
  25. }
  26. else {//load the splash from the DEfault image or from LaunchImage in the xcassets
  27. CGFloat screenHeight = screenBounds.size.height;
  28. NSString* imageName = @"Default";
  29. if (screenHeight == 568)
  30. imageName = [imageName stringByAppendingString:@"-568h"];
  31. else if (screenHeight == 667)
  32. imageName = [imageName stringByAppendingString:@"-667h"];
  33. else if (screenHeight == 736)
  34. imageName = [imageName stringByAppendingString:@"-736h"];
  35. else if (screenHeight == 812)
  36. imageName = [imageName stringByAppendingString:@"-812h"];
  37. //xcassets LaunchImage files
  38. UIImage *image = [UIImage imageNamed:imageName];
  39. if (image == nil) {
  40. imageName = @"LaunchImage";
  41. if (screenHeight == 480)
  42. imageName = [imageName stringByAppendingString:@"-700"];
  43. if (screenHeight == 568)
  44. imageName = [imageName stringByAppendingString:@"-700-568h"];
  45. else if (screenHeight == 667)
  46. imageName = [imageName stringByAppendingString:@"-800-667h"];
  47. else if (screenHeight == 736)
  48. imageName = [imageName stringByAppendingString:@"-800-Portrait-736h"];
  49. else if (screenHeight == 812)
  50. imageName = [imageName stringByAppendingString:@"-1100-Portrait-2436h"];
  51. else if (screenHeight == 375)
  52. imageName = [imageName stringByAppendingString:@"-1100-Landscape-2436h"];
  53. else if (screenHeight == 828)
  54. imageName = [imageName stringByAppendingString:@"-1200-Portrait-1792h"];
  55. else if (screenHeight == 896)
  56. imageName = [imageName stringByAppendingString:screenScale == 2. ? @"-1200-Portrait-1792h" : @"-1200-Portrait-2688h"];
  57. image = [UIImage imageNamed:imageName];
  58. }
  59. if (image != nil) {
  60. viewController = [[RNNSplashScreen alloc] init];
  61. viewController.view = [[UIImageView alloc] initWithImage:image];
  62. }
  63. }
  64. if (viewController != nil) {
  65. id<UIApplicationDelegate> appDelegate = [UIApplication sharedApplication].delegate;
  66. appDelegate.window.rootViewController = viewController;
  67. [appDelegate.window makeKeyAndVisible];
  68. }
  69. }
  70. - (UIStatusBarStyle)preferredStatusBarStyle {
  71. NSString *styleString = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"UIStatusBarStyle"];
  72. if ([styleString isEqualToString:@"UIStatusBarStyleLightContent"])
  73. return UIStatusBarStyleLightContent;
  74. return UIStatusBarStyleDefault;
  75. }
  76. - (BOOL)prefersStatusBarHidden {
  77. return [[[NSBundle mainBundle] objectForInfoDictionaryKey:@"UIStatusBarHidden"] boolValue];
  78. }
  79. @end