ios6中的方向问题

aja*_*jay 1 uinavigationcontroller ipad presentmodalviewcontroller ios6

我在我的应用程序中使用UINavigationController,我的第一个控制器叫做A,它只对portrite有严格要求,我的A控制器中有一个按钮.一旦我点击按钮,我就会在另一个名为B的视图控制器上创建实例.在为BI创建实例后,使用以下方法进行模态呈现

[self presentViewController:BInstance animated:YES completion:^{
            NSLog(@"completed");
        }];
Run Code Online (Sandbox Code Playgroud)

我的B控制器能够支持所有方向,这是预期的,直到ios5.1及更早版本.现在我正在尝试使用Xcode4.5在ios6上运行我的项目它没有被轮换我期待解决这个问题我发现了一些关于shouldAutorotateToInterfaceOrientation 的博客:方法从最新的ios6中被弃用了.我也用过替代品

-(BOOL)shouldAutorotate{
    return YES;
}
-(NSUInteger)supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskAll;
}
Run Code Online (Sandbox Code Playgroud)

但仍然没有太多预期的结果.

问题:什么使我的B控制器适用于所有方向,即使我的父A只适用于portrite.

在此先感谢您对此有用的所有建议/建议.

may*_*uur 5

首先,在AppDelegate中,写下这个.这是非常重要的

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
     return (UIInterfaceOrientationMaskAll);
}
Run Code Online (Sandbox Code Playgroud)

然后,对于只需要PORTRAIT模式的UIViewControllers ,编写这些函数

- (BOOL)shouldAutorotate
{
    return YES;
}

- (NSUInteger)supportedInterfaceOrientations
{
    return (UIInterfaceOrientationMaskPortrait);
}
Run Code Online (Sandbox Code Playgroud)

对于也需要LANDSCAPE的 UIViewControllers,将掩码更改为All.

- (NSUInteger)supportedInterfaceOrientations
{
    return (UIInterfaceOrientationMaskAllButUpsideDown);
    //OR return (UIInterfaceOrientationMaskAll);
}
Run Code Online (Sandbox Code Playgroud)

现在,如果要在Orientation更改时进行一些更改,请使用此功能.

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{

}
Run Code Online (Sandbox Code Playgroud)