gpt4 book ai didi

objective-c - 自动旋转 iOS 8 导航 Controller

转载 作者:行者123 更新时间:2023-12-03 21:01:10 25 4
gpt4 key购买 nike

我有某些由UINavigationController(推送和弹出)管理的viewControllers。我想将不同的 viewControllers 限制为不同的 orientation,例如第一个应该仅在 Portrait 中,第二个在 portrait 中,landscape 中的第三个和第四个可以是 portraitlandscape 两者。我在 storyBoardisInitialViewController 上设置了一个 ViewController

- (BOOL) shouldAutorotate{
return NO;

}

工作没有任何问题,但是当我将导航 Controller (通过推送和弹出管理这四个 View )设置为storyBoard中的isInitialViewController时,该函数停止被调用,现在自动。如何使用此 UINavigationController 作为 isInitialViewController 停止自动旋转这些 View 。我使用以下函数取决于它是哪个 ViewController

- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
return (interfaceOrientation == UIDeviceOrientationPortrait);//choose portrait or landscape}

- (BOOL) shouldAutorotate{
return NO;
}

- (NSUInteger)supportedInterfaceOrientations
{
//return UIInterfaceOrientationMaskLandscape;
return UIInterfaceOrientationMaskPortrait;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
// return UIInterfaceOrientationLandscapeLeft |
// UIInterfaceOrientationLandscapeRight;
return UIInterfaceOrientationPortrait;
}

最佳答案

只需子类 UINavigationController 并重写适当的方法:

.h 文件:

@interface CustomUINavigationController : UINavigationController
@property BOOL canRotate;
@end

.m 文件:

@implementation CustomUINavigationController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}



- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationPortrait;
}

- (BOOL)shouldAutorotate
{
return self.canRotate;
}
@end

关于objective-c - 自动旋转 iOS 8 导航 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30844898/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com