当我将自定义UIViewController添加到窗口时,如何摆脱差距?

时间:2010-04-02 09:11:25

标签: iphone uiview

添加自定义UIViewController的视图后,我在窗口底部出现了这个空白。在移动到另一个视图然后返回之后视图向下移动时,间隙消失了。

以下是app delegate中的代码:

- (void)applicationDidFinishLaunching:(UIApplication *)application {    

    // Override point for customization after application launch
    CustomViewController *gvc = [[CustomViewController alloc] init];
    self.customViewController = gvc;
    [gvc release];

    [window addSubview:customViewController.view];
    [window makeKeyAndVisible];
}

“CustomViewController”用作根视图控制器,以简单地协调要显示的其他UIViewControllers。因此,我只需将其view =设置为所需的第一个ViewController视图,如下所示:

 - (void)loadView { 
     UIView *v = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
     self.view = v;
     [v release];

     // Add the HomeViewController to the top of the stack
     MainViewController *mvc = [[MainViewController alloc] initWithNibName:@"MainView" bundle:nil];
     mvc.delegate = self;
     self.mainViewController = mvc;
     [mvc release];

     [self.view addSubview:self.mainViewController.view];
 }

我尝试了很多东西,包括你在这里看到的没有运气的东西。有什么想法吗?

感谢

1 个答案:

答案 0 :(得分:0)

这一行

UIView *v = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];

应该是......

UIView *v = [[UIView alloc] initWithFrame:CGRectMake(0, 20, 320, 460)];

美好时光。