我有一个希望在外部屏幕上显示的应用程序。
问题是,当我去硬件 - > 外部显示器并选择其中之一时 - 事件不会被触发。为什么?
这也不会被输入:
if ([[UIScreen screens] count] > 1)
所以我添加了下一个代码:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//SOME CODE ...
[self checkForExistingScreenAndInitializeIfPresent];
[self setUpScreenConnectionNotificationHandlers];
return YES:
}
- (void)checkForExistingScreenAndInitializeIfPresent
{
if ([[UIScreen screens] count] > 1)
{
// Get the screen object that represents the external display.
UIScreen *secondScreen = [[UIScreen screens] objectAtIndex:1];
// Get the screen's bounds so that you can create a window of the correct size.
CGRect screenBounds = secondScreen.bounds;
self.secondWindow = [[UIWindow alloc] initWithFrame:screenBounds];
self.secondWindow.screen = secondScreen;
self.externalWindow=[[ExternalDisplayViewController alloc]initWithNibName:@"ExternalDisplayViewController" bundle:nil];
self.externalWindow.view.frame=screenBounds;
self.secondWindow.rootViewController=self.externalWindow;
// Set up initial content to display...
// Show the window.
self.secondWindow.hidden = NO;
}
}
- (void)setUpScreenConnectionNotificationHandlers
{
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
[center addObserver:self selector:@selector(handleScreenDidConnectNotification:)
name:UIScreenDidConnectNotification object:nil];
[center addObserver:self selector:@selector(handleScreenDidDisconnectNotification:)
name:UIScreenDidDisconnectNotification object:nil];
}
添加:
刚刚尝试在 ViewDidLoad 中添加代码
添加了这个:
// Check for external screen.
if ([[UIScreen screens] count] > 1)
{
}
else {
}
已打开外部显示器和模拟器 - 不进入 IF 块