#pragma mark - LandScapeUINavigation
@interface UINavigationController (LandScapeUINavigation)
- (BOOL)shouldAutorotate;
@end
@implementation UINavigationController (LandScapeUINavigation)
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
//NSLog(@"Nav shouldAutorotateToInterfaceOrientation");
return [self.topViewController shouldAutorotateToInterfaceOrientation:interfaceOrientation];
}
- (BOOL)shouldAutorotate
{
//NSLog(@"Nav shouldAutorotate");
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
//NSLog(@"Nav supportedInterfaceOrientations:%ld", [self.topViewController supportedInterfaceOrientations]);
return [self.topViewController supportedInterfaceOrientations];
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
//NSLog(@"Nav preferredInterfaceOrientationForPresentation");
return [self.topViewController preferredInterfaceOrientationForPresentation];
}
- (UIStatusBarStyle)preferredStatusBarStyle {
return [self.topViewController preferredStatusBarStyle];
}
- (BOOL)prefersStatusBarHidden
{
return [self.topViewController prefersStatusBarHidden];
}
@end
本文介绍了如何通过扩展 UIKit 中的 UINavigationController 类来实现设备方向的自动旋转功能。具体包括 shouldAutorotateToInterfaceOrientation、shouldAutorotate 和 supportedInterfaceOrientations 等方法的实现,确保导航控制器及其子视图控制器能够正确地响应设备的方向变化。
747

被折叠的 条评论
为什么被折叠?



