0

navigationBar親View Controllerに表示しています:

- (void)viewWillDisappear:(BOOL)animated
{
    [self.navigationController setNavigationBarHidden:NO animated:YES];
    [super viewWillDisappear:animated];
}

次に、次のView Controllerで

- (void)viewDidLoad
{
    /* ... */
    NSLog(@"%i, %g", self.navigationController.navigationBarHidden,
            self.view.frame.size.height);
}

- (void)viewWillAppear:(BOOL)animated
{
    /* ... */
    [super viewWillAppear:animated];
    NSLog(@"%i, %g", self.navigationController.navigationBarHidden, 
            self.view.frame.size.height);
}

- (void)viewWillLayoutSubviews
{
    NSLog(@"%i, %g", self.navigationController.navigationBarHidden, 
            self.view.frame.size.height);
}

- (void)viewDidAppear:(BOOL)animated
{
    NSLog(@"%i, %g", self.navigationController.navigationBarHidden, 
            self.view.frame.size.height);
}

出力:

-[viewDidLoad]: 1, 416
-[viewWillAppear:]: 0, 460
-[viewWillLayoutSubviews]: 0, 416
-[viewDidAppear:]: 0, 416

ご覧のとおり、viewWillAppear間違っていself.view.frame.size.heightます。使ってもいいのですviewWillLayoutSubviewsが、iOS5で導入されました。viewWillAppear で適切なフレームの高さを取得することは可能ですか?

4

1 に答える 1

2

これが私がこれまでに得た最良の解決策です:

- (void)viewWillAppear:(BOOL)animated
{
    /* recalculate frame size */
    CGSize size = [UIScreen mainScreen].bounds.size;
    UIApplication *application = [UIApplication sharedApplication];
    if (UIInterfaceOrientationIsLandscape(application.statusBarOrientation))
        size = CGSizeMake(size.height, size.width);
    if (!application.statusBarHidden)
        size.height -= MIN(application.statusBarFrame.size.width,
                           application.statusBarFrame.size.height);

    CGRect frame = self.view.frame;
    frame.size.height = size.height -
                        self.navigationController.navigationBar.frame.size.height;
    self.view.frame = frame;

    /* ... */
}
于 2012-10-08T08:33:17.050 に答える