- (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)
这在文档中很容易找到.在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)