我的应用程序是基于导航的,主要以纵向方式运行,但是一个视图控制器支持纵向和横向 . 现在的问题是,当我从横向视图控制器推送新的视图控制器时,新的视图控制器也被推入横向模式,虽然我想要它在纵向模式 .
此外,当我从横向控制器弹出视图控制器时,Poped视图控制器将以纵向模式显示 .
我不知道我的代码有什么问题 .
这是我的代码段和用于这些方向支持的信息 .
在info.plist文件中,我一直支持所有方向,但肖像颠倒 .
我还添加了导航控制器类别的类别,如下所示 .
@implementation UINavigationController(Rotation_IOS6)
-(BOOL)shouldAutorotate
{
return [[self.viewControllers lastObject] shouldAutorotate];
}
-(NSUInteger)supportedInterfaceOrientations
{
return [[self.viewControllers lastObject] supportedInterfaceOrientations];
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
}
@end
我还创建了一个UIViewController子类,它充当所有类的超类 . 以下是超类的定位方法 .
@implementation ParentViewController
- (BOOL)shouldAutorotate{
return NO;
}
- (NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskPortrait;
}
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{
return (toInterfaceOrientation == UIInterfaceOrientationPortrait);
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
return UIInterfaceOrientationPortrait;
}
@end
支持景观的定向方法控制器如下 .
@implementation LandscapeController
#pragma mark -
#pragma mark Orientation Methods
- (BOOL)shouldAutorotate{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskPortrait|UIInterfaceOrientationMaskLandscape;
}
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{
return (toInterfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
@end
提前致谢 .
2 回答
这是推送view.take一个对象开关的方法
在switch.m
您可以使用上述方法从横向模式推送到纵向视图
在景观视图controller.m
我遇到过类似的问题 . 在我的情况下,这个非常一个视图控制器必须始终以横向显示,并且在返回的路上必须将其他视图控制器设置回纵向 .
我在FAQ中找到了以下解决方案:iPhone Landscape FAQ and Solutions
这个想法的关键点是只能通过一种方式强制设备进入某个方向:1 . 设置状态栏的方向 . 2.以模态方式呈现任何支持目标方向的视图控制器(!) .
那么,你不想以模态呈现任何东西?别担心 . 没有什么可以阻止你...... 3.一旦它被呈现就立即解雇那个视图控制器 . 当你这样做时,它甚至不会被用户看到 . 但一旦完成,您的设备仍然处于这个方向 . 4.如果您使用故事板,请按下要显示的视图控制器,甚至可以将其转换为视图控制器 .
对我来说,这似乎是唯一可行的解决方案 . 除了FAQ中的答案之外,其他所有内容也必须正确设置 . 完整项目支持的设备方向必须基本上全部 . 每个视图控制器支持的方向必须是每个视图控制器支持的方向,并且
shouldAutoRotate
应该返回YES
. 如果涉及标签栏控制器,则会变得更加困难 . 如果您的应用基于标签栏,请与我联系 .