【问题标题】:Show screen on external display在外部显示器上显示屏幕
【发布时间】:2012-07-27 16:15:21
【问题描述】:

我在 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;
}

【问题讨论】:

    标签: ios5 uistoryboard


    【解决方案1】:

    如果您想看到的不仅仅是黑屏,您需要输入一些内容。一种选择是添加如下内容:

    UIView *myCustomUIView = [[MyCustomUIView alloc] initWithFrame:frame];
    [window addSubview:myCustomUIView];
    

    然后在视图的 drawRect:(CGRect) 方法中绘制东西。

    希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-12-09
      • 1970-01-01
      • 1970-01-01
      • 2019-03-20
      • 1970-01-01
      • 2021-10-30
      • 1970-01-01
      • 2016-10-07
      相关资源
      最近更新 更多