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;
}
4

1 に答える 1

0

黒い画面以上のものを見たい場合は、何らかのコンテンツを入れる必要があります。1 つのオプションは、次のようなものを追加することです。

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

次に、ビューの drawRect:(CGRect) メソッドで何かを描画します。

お役に立てれば。

于 2012-08-07T04:44:29.750 に答える