iPhone: UINavigationBar with buttons - adjust the height

廉价感情. 提交于 2019-11-30 05:21:05

I figured it out: The height of the navigation bar must be 32 px! With 33 or 34 px the alignment screws up.

Here's the code I wrote based on crashtesttommy's answer:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return YES;
}

- (void) correctNavBarHeightForOrientation:(UIInterfaceOrientation)orientation {
    // This is only needed in on the iPhone, since this is a universal app, check that first.
    if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone){
        if (UIInterfaceOrientationIsLandscape(orientation)) {
            self.navBar.frame = CGRectMake(self.navBar.frame.origin.x, self.navBar.frame.origin.y, self.navBar.frame.size.width, 32.0f);
        } else {
            self.navBar.frame = CGRectMake(self.navBar.frame.origin.x, self.navBar.frame.origin.y, self.navBar.frame.size.width, 44.0f);
        }
    }  
}

- (void) viewWillAppear:(BOOL)animated {
    [self correctNavBarHeightForOrientation:[UIApplication sharedApplication].statusBarOrientation];
}

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
    [self correctNavBarHeightForOrientation:toInterfaceOrientation];
}

Create alternate images, and in the view controller methods that handle animating the rotation, change the images in the bar button items. Or you could probably use a UIImageView as a custom view in your item, and set its content mode to scale the image down.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!