react-native-navigation的迁移库

RNNSplashScreen.m 2.8KB

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