react-native-navigation的迁移库

RNNSplashScreen.m 3.1KB

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