Przeglądaj źródła

Support storyboards in the splash screen (#3459)

Johan Flint 6 lat temu
rodzic
commit
b16d14c90b
1 zmienionych plików z 13 dodań i 12 usunięć
  1. 13
    12
      lib/ios/RNNSplashScreen.m

+ 13
- 12
lib/ios/RNNSplashScreen.m Wyświetl plik

@@ -10,22 +10,25 @@
10 10
 	UIApplication.sharedApplication.delegate.window.backgroundColor = [UIColor whiteColor];
11 11
 	
12 12
 	CGRect screenBounds = [UIScreen mainScreen].bounds;
13
-	UIView *splashView = nil;
13
+	UIViewController *viewController = nil;
14 14
 	
15 15
 	NSString* launchStoryBoard = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"UILaunchStoryboardName"];
16 16
 	if (launchStoryBoard != nil) {//load the splash from the storyboard that's defined in the info.plist as the LaunchScreen
17 17
 		@try
18 18
 		{
19
-			splashView = [[NSBundle mainBundle] loadNibNamed:launchStoryBoard owner:self options:nil][0];
19
+			UIStoryboard *storyboard = [UIStoryboard storyboardWithName:launchStoryBoard bundle:nil];
20
+			viewController = [storyboard instantiateInitialViewController];
21
+		}
22
+		@catch(NSException *e)
23
+		{
24
+			UIView *splashView = [[NSBundle mainBundle] loadNibNamed:launchStoryBoard owner:self options:nil][0];
20 25
 			if (splashView != nil)
21 26
 			{
22 27
 				splashView.frame = CGRectMake(0, 0, screenBounds.size.width, screenBounds.size.height);
28
+				viewController = [[RNNSplashScreen alloc] init];
29
+				viewController.view = splashView;
23 30
 			}
24 31
 		}
25
-		@catch(NSException *e)
26
-		{
27
-			splashView = nil;
28
-		}
29 32
 	}
30 33
 	else {//load the splash from the DEfault image or from LaunchImage in the xcassets
31 34
 		CGFloat screenHeight = screenBounds.size.height;
@@ -60,16 +63,14 @@
60 63
 		}
61 64
 		
62 65
 		if (image != nil) {
63
-			splashView = [[UIImageView alloc] initWithImage:image];
66
+			viewController = [[RNNSplashScreen alloc] init];
67
+			viewController.view = [[UIImageView alloc] initWithImage:image];
64 68
 		}
65 69
 	}
66 70
 	
67
-	if (splashView != nil) {
68
-		RNNSplashScreen *splashVC = [[RNNSplashScreen alloc] init];
69
-		splashVC.view = splashView;
70
-		
71
+	if (viewController != nil) {
71 72
 		id<UIApplicationDelegate> appDelegate = [UIApplication sharedApplication].delegate;
72
-		appDelegate.window.rootViewController = splashVC;
73
+		appDelegate.window.rootViewController = viewController;
73 74
 		[appDelegate.window makeKeyAndVisible];
74 75
 	}
75 76
 }