react-native-navigation的迁移库

RNNSplashScreen.m 2.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. //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. @end