我在 Github 上查看了一些示例,但所有示例都没有使用情节提要。
我试图在我的应用程序中使用该代码,但我在模拟器的外部设备上看到的只是黑屏。
我现在拥有的代码:
if([[UIScreen screens]count] > 1) {
CGSize maxSize;
UIScreenMode *maxScreenMode;
for(int i = 0; i < [[[[UIScreen screens] objectAtIndex:1] availableModes]count]; i++)
{
UIScreenMode *current = [[[[UIScreen screens]objectAtIndex:1]availableModes]objectAtIndex:i];
if(current.size.width > maxSize.width)
{
maxSize = current.size;
maxScreenMode = current;
}
}
UIScreen *externalScreen = [[UIScreen screens] objectAtIndex:1];
externalScreen.currentMode = maxScreenMode;
[self myScreenInit:externalScreen];
}
- (void) screenDidConnect:(NSNotification *)notification {
[self myScreenInit:[notification object]];
}
- (void) myScreenInit:(UIScreen *)connectedScreen {
CGRect frame = connectedScreen.bounds;
UIWindow *window = [[UIWindow alloc] initWithFrame:frame];
window.backgroundColor = [UIColor whiteColor];
[window setScreen:connectedScreen];
window.hidden = NO;
}