react-native-navigation的迁移库

RNNSplashScreen.m 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. UIView *splashView = 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. splashView = [[NSBundle mainBundle] loadNibNamed:launchStoryBoard owner:self options:nil][0];
  14. if (splashView != nil)
  15. {
  16. splashView.frame = CGRectMake(0, 0, screenBounds.size.width, screenBounds.size.height);
  17. }
  18. }
  19. @catch(NSException *e)
  20. {
  21. splashView = nil;
  22. }
  23. }
  24. else {//load the splash from the DEfault image or from LaunchImage in the xcassets
  25. CGFloat screenHeight = screenBounds.size.height;
  26. NSString* imageName = @"Default";
  27. if (screenHeight == 568)
  28. imageName = [imageName stringByAppendingString:@"-568h"];
  29. else if (screenHeight == 667)
  30. imageName = [imageName stringByAppendingString:@"-667h"];
  31. else if (screenHeight == 736)
  32. imageName = [imageName stringByAppendingString:@"-736h"];
  33. //xcassets LaunchImage files
  34. UIImage *image = [UIImage imageNamed:imageName];
  35. if (image == nil) {
  36. imageName = @"LaunchImage";
  37. if (screenHeight == 480)
  38. imageName = [imageName stringByAppendingString:@"-700"];
  39. if (screenHeight == 568)
  40. imageName = [imageName stringByAppendingString:@"-700-568h"];
  41. else if (screenHeight == 667)
  42. imageName = [imageName stringByAppendingString:@"-800-667h"];
  43. else if (screenHeight == 736)
  44. imageName = [imageName stringByAppendingString:@"-800-Portrait-736h"];
  45. else if (screenHeight == 812)
  46. imageName = [imageName stringByAppendingString:@"-1100-Portrait-2436h"];
  47. else if (screenHeight == 375)
  48. imageName = [imageName stringByAppendingString:@"-1100-Landscape-2436h"];
  49. image = [UIImage imageNamed:imageName];
  50. }
  51. if (image != nil) {
  52. splashView = [[UIImageView alloc] initWithImage:image];
  53. }
  54. }
  55. if (splashView != nil) {
  56. RNNSplashScreen *splashVC = [[RNNSplashScreen alloc] init];
  57. splashVC.view = splashView;
  58. id<UIApplicationDelegate> appDelegate = [UIApplication sharedApplication].delegate;
  59. appDelegate.window.rootViewController = splashVC;
  60. [appDelegate.window makeKeyAndVisible];
  61. }
  62. }
  63. @end