react-native-navigation的迁移库

RNNSplashScreen.m 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #import "RNNSplashScreen.h"
  2. #import <UIKit/UIKit.h>
  3. @implementation RNNSplashScreen
  4. -(void)showSplashScreen
  5. {
  6. CGRect screenBounds = [UIScreen mainScreen].bounds;
  7. UIView *splashView = nil;
  8. NSString* launchStoryBoard = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"UILaunchStoryboardName"];
  9. if (launchStoryBoard != nil)
  10. {//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
  25. {//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. //xcassets LaunchImage files
  35. UIImage *image = [UIImage imageNamed:imageName];
  36. if (image == nil)
  37. {
  38. imageName = @"LaunchImage";
  39. if (screenHeight == 480)
  40. imageName = [imageName stringByAppendingString:@"-700"];
  41. if (screenHeight == 568)
  42. imageName = [imageName stringByAppendingString:@"-700-568h"];
  43. else if (screenHeight == 667)
  44. imageName = [imageName stringByAppendingString:@"-800-667h"];
  45. else if (screenHeight == 736)
  46. imageName = [imageName stringByAppendingString:@"-800-Portrait-736h"];
  47. image = [UIImage imageNamed:imageName];
  48. }
  49. if (image != nil)
  50. {
  51. splashView = [[UIImageView alloc] initWithImage:image];
  52. }
  53. }
  54. if (splashView != nil)
  55. {
  56. UIViewController *splashVC = [[UIViewController 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