我的故事板中有 2 个 UIViewController,第一个(本地视图控制器)显示在我的 ipad 窗口中。故事板中还有第二个(外部视图控制器)
我想将第二个 UIViewController(外部视图控制器)的视图及其内容发送到我创建的另一个窗口以发送到外部显示器。
我可以创建一个 UIwindow 并将其发送到外部显示器(UIScreen = 1),我可以向它添加一个视图,然后向它添加标签之类的东西就好了。(它们显示在第二个显示器上)
但是,如果我想将 UIviewcontroller“视图”(及其所有内容)发送到我为外部显示器创建的 Windows……我看不到它。
我可以这样做吗?
看看下面的代码:
//this code is at my main view controller
#import "ASHExternalViewController.h" //for External View Controller
if ([[UIScreen screens] count] > 1)
{
// Associate the window with the second screen.
// The main screen is always at index 0.
UIScreen* secondScreen = [[UIScreen screens] objectAtIndex:1];
CGRect screenBounds = secondScreen.bounds;
//Alloc external window
UIWindow *externalWindow = [[UIWindow alloc] initWithFrame:screenBounds];
externalWindow.screen = secondScreen;
// Add a white background View to the window
UIView* whiteField = [[UIView alloc] initWithFrame:screenBounds];
whiteField.backgroundColor = [UIColor whiteColor];
[externalWindow addSubview:whiteField];
//up to this point all OK, I can see the white background view in the external display
//
//Add uiviewcontoller at storyborad to external window
ASHExternalViewController *_externalView = [[ASHExternalViewController alloc] initWithNibName:@"ASHExternalViewController" bundle:nil];
[whiteField addSubview: externalView.view];
//does no add the view in the external UIViewController in story board
// Go ahead and show the window.
externalWindow.hidden = NO;
}