旋转时隐藏导航栏

Dom*_*ess 6 cocoa-touch

我有一个带导航栏的UIView.当用户将iPhone横向放置并在纵向视图上再次显示时,如何隐藏导航栏?

ada*_*dam 9

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
    [[self navigationController] setNavigationBarHidden:UIInterfaceOrientationIsLandscape(toInterfaceOrientation) animated:YES];
    [[UIApplication sharedApplication] setStatusBarHidden:UIInterfaceOrientationIsLandscape(toInterfaceOrientation) animated:YES];
}
Run Code Online (Sandbox Code Playgroud)


Aug*_*ust 7

这在文档中很容易找到.在UINavigationController文档中,要隐藏导航栏,请使用:

- (void)setNavigationBarHidden:(BOOL)hidden animated:(BOOL)animated
Run Code Online (Sandbox Code Playgroud)

如果要在设备旋转时执行此操作,则需要在视图控制器方法中执行此操作(在UIViewController文档中提到):

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
Run Code Online (Sandbox Code Playgroud)