0

少し問題がありますが、内訳は次のとおりです。

私の AppDelegate は、rootViewController としてビュー コントローラーを使用します。このビュー コントローラの目的は、他のいくつかのビュー コントローラを入れ替えて、ログイン画面とメイン画面と呼ぶことです。簡単にするために、投稿するコードからスワッピング コードを削除し、rootViewController に最初のコンテンツ ビュー コントローラーを表示するだけにしています (たとえば、ログイン)。

私が抱えている問題は、コンテンツ ビュー コントローラーが rootViewController 内で少し押し下げられているように見えることです。rootViewController には青色の背景を、コンテンツ ビュー コントローラーにはオレンジ色の背景を指定しました。これが私のコードです:

AppDelegate.h

#import <UIKit/UIKit.h>

@class MainViewController;

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) MainViewController *main;

@end

AppDelegate.m

#import "AppDelegate.h"
#import "MainViewController.h"

@implementation AppDelegate

@synthesize main;

- (void)dealloc
{
    [_window release];
    [main release];
    [super dealloc];
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];

    MainViewController *mainVC = [[MainViewController alloc] init];
    self.main = mainVC;
    self.window.rootViewController = self.main;

    [self.window makeKeyAndVisible];

    return YES;
}

MainViewController.h

#import <UIKit/UIKit.h>

@class ContentViewController;

@interface MainViewController : UIViewController

@property (nonatomic, retain) ContentViewController *content;

@end

MainViewController.m

#import "MainViewController.h"
#import "ContentViewController.h"

@implementation MainViewController

@synthesize content;

- (id)init
{
self = [super init];
    if (self ) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.view.backgroundColor = [UIColor blueColor];

    ContentViewController *viewController = [[ContentViewController alloc] init];
    self.content = viewController;
    [self.view insertSubview:self.content.view atIndex:0];              
}

- (void)dealloc {
    [content release];  
    [super dealloc];
}

@end

ContentViewController.h

#import <UIKit/UIKit.h>

@interface LoginVC : UIViewController

@end

ContentViewController.m

#import "ContentViewController.h"

@implementation ContentViewController

- (id)init
{
    self = [super init];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    self.view.backgroundColor = [UIColor orangeColor];
}

- (void)dealloc {
    [super dealloc];
}

@end

上記のコードは、その下に青いストリップ (ステータス バーのほぼ高さ) を持つステータス バー (メイン ビュー コントローラー) を表示し、その後にオレンジ色のコンテンツ ビュー コントローラーが画面の残りの部分を占めます。何らかの理由で、メイン ビュー コントローラーがコンテンツ ビュー コントローラーを少し押し下げているようです。

奇妙なことに、View Controller を作成し、ビューの描画に XIB を使用すると、問題なく表示され、メイン ビューの上部にコンテンツ ビューが表示されます。

誰かがこの問題に光を当てることができれば、私はそれを非常に感謝しています.

乾杯

4

1 に答える 1