react-native-navigation的迁移库

RNNSplashScreen.m 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. image = [UIImage imageNamed:imageName];
  46. }
  47. if (image != nil) {
  48. splashView = [[UIImageView alloc] initWithImage:image];
  49. }
  50. }
  51. if (splashView != nil) {
  52. RNNSplashScreen *splashVC = [[RNNSplashScreen alloc] init];
  53. splashVC.view = splashView;
  54. id<UIApplicationDelegate> appDelegate = [UIApplication sharedApplication].delegate;
  55. appDelegate.window.rootViewController = splashVC;
  56. [appDelegate.window makeKeyAndVisible];
  57. }
  58. }
  59. @end