0

我有父视图控制器和另一个模态视图控制器。我在父级上下文中展示了模态视图控制器:

readingViewController * reading_view_controller = [[readingViewController alloc] initWithNibName:@"readingViewController" bundle:nil];
[self setModalPresentationStyle:UIModalPresentationCurrentContext];
[self presentModalViewController:reading_view_controller animated:YES];

父视图控制器不会定向横向;所以,我在父视图控制器中添加了这些方法:

- (NSUInteger)supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskPortraitUpsideDown|UIInterfaceOrientationMaskPortrait;
}


-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{
    return (toInterfaceOrientation == UIInterfaceOrientationPortrait || toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown);
}

呈现的 viewController(模态呈现)应该面向所有可能的方向;所以,我添加了这些方法:

- (NSUInteger)supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskAll;
}

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{

    return YES;
}

但是,因为我假设(UIModalPresentationCurrentContext),呈现的 viewController 在 IOS 6.0 中没有定向,而它在 IOS 5.0 中按预期工作

请问如何解决这个问题?

4

2 回答 2

1

如果您有一个基于选项卡的应用程序,则首先在应用程序委托中添加一些代码,然后self.window.rootviewcontroller-self.tabbarcontroller.

        @implementation UITabBarController (SK8FASTR2App)
        -(BOOL)shouldAutorotate
        {
            return YES;
        }

        - (NSUInteger)supportedInterfaceOrientations
        {
            // your custom logic for rotation of selected tab
             if (self.selectedIndex==3){
             return UIInterfaceOrientationMaskPortrait;
             }
             else {
            UIInterfaceOrientationMaskPortrait|UIInterfaceOrientationMaskPortraitUpsideDown|UIInterfaceOrientationLandscapeLeft|UIInterfaceOrientationLandscapeRight;
             return UIInterfaceOrientationMaskAll;
             }

        }

        @end



        before

        @implementation AppDelegate


    - (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
            return  UIInterfaceOrientationMaskAll;
    }

更改该课程的方向

-(BOOL)shouldAutorotate
{
    return NO;
}

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscapeRight;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationLandscapeRight;
}
于 2013-04-26T10:28:24.813 回答
0

你应该实施

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation;

例如:-

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationMaskAll;
}
于 2013-01-19T10:18:16.750 回答