下面是ECSlidingViewController演示代码的 applicationDidFinishLaunching 方法:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
ECSlidingViewController *slidingViewController = (ECSlidingViewController *)self.window.rootViewController;
UIStoryboard *storyboard;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
storyboard = [UIStoryboard storyboardWithName:@"iPhone" bundle:nil];
} else if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
storyboard = [UIStoryboard storyboardWithName:@"iPad" bundle:nil];
}
slidingViewController.topViewController = [storyboard instantiateViewControllerWithIdentifier:@"FirstTop"];
return YES;
}
对我来说没有意义的是第一行:
ECSlidingViewController *slidingViewController = (ECSlidingViewController*)self.window.rootViewController;
我只是不明白你怎么能抓住窗口的根视图控制器,然后像你喜欢的那样投射它?那条线到底是做什么的,它是如何工作的?