我在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;
}
答案 0 :(得分:0)
如果您想看到的不仅仅是黑屏,还需要输入一些内容。一种选择是添加如下内容:
UIView *myCustomUIView = [[MyCustomUIView alloc] initWithFrame:frame];
[window addSubview:myCustomUIView];
然后在视图的drawRect:(CGRect)方法中绘制东西。
希望这有帮助。