react-native-navigation的迁移库

RNNSplashScreen.m 2.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. @end