我有一个带有导航控制器的VC。也不应该自动旋转,它们都不会在屏幕上显示。但如果我在横向模式下解除VC2,VC1将处于横向模式..
这就是我所拥有的: VC1:
UINavigationController *navigationController = [[UINavigationController alloc]
initWithRootViewController:VC2];
navigationController.modalPresentationStyle=UIModalPresentationFullScreen;
navigationController.navigationBar.barStyle=UIBarStyleDefault;
navigationController.navigationBar.backgroundColor = [UIColor whiteColor];
navigationController.navigationBar.translucent = YES;
navigationController.delegate=self;
[self presentViewController:navigationController animated:YES completion:nil];
-(BOOL)shouldAutorotate
{
return NO;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
VC2:
-(BOOL)shouldAutorotate
{
return NO;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
我在UINavigationController上也有一个类别,它帮助我在其他屏幕上设置方向。
- (BOOL)shouldAutorotate {
if ([self.topViewController respondsToSelector:@selector(shouldAutorotate)]) {
return [self.topViewController shouldAutorotate];
} else {
return YES;
}
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
if ([self.topViewController respondsToSelector:@selector(preferredInterfaceOrientationForPresentation)]) {
return [self.topViewController preferredInterfaceOrientationForPresentation];
}
return self.interfaceOrientation;
}
- (NSUInteger)supportedInterfaceOrientations {
if ([self.topViewController respondsToSelector:@selector(supportedInterfaceOrientations)]) {
return [self.topViewController supportedInterfaceOrientations];
}
return UIInterfaceOrientationMaskAll;
}