2012-07-27 67 views
0

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

如果你想看到比黑屏,你就需要把一些內容更多。一種選擇是添加如下內容:

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

然後在視圖的drawRect:(CGRect)方法中繪製東西。

希望這會有所幫助。

+0

謝謝,但問題是,如果我使用故事板它不工作... – Shmidt 2012-08-07 21:07:05