定向景观 - >肖像不起作用

时间:2011-11-07 11:16:58

标签: ios xcode uinavigationcontroller orientation modalviewcontroller

我有另一个方向问题。但这个非常棘手。 我的RootViewController是一个普通的NavigationController。

self.window.rootViewController = _naviController;

里面有另一个ViewController,让我们称之为VC1。 VC1有一些按钮和标签。它就像文件夹的概述一样。

如果我按下一个按钮,我会带着3个ViewController(Page)到另一个ViewController和另一堆按钮(比如在里面查看图片/缩略图的文件夹里):

Archiv *archiv = [[Archiv alloc] init];
[self.navigationController pushViewController:archiv animated:YES];
[archiv release];
在loadView中

firstPage = [[Page alloc] initViewWithFrame:CGRectMake(0, 0, 768, 960)];
[firstPage setRootViewController:self];
secondPage = [[Page alloc] initViewWithFrame:CGRectMake(0, -960, 768, 960)];
[secondPage setRootViewController:self];
thirdPage = [[Page alloc] initViewWithFrame:CGRectMake(0, 960, 768, 960)];
[thirdPage setRootViewController:self];

如果我现在再次单击一个按钮,则活动页面会推送我的第三个ViewController(带有调整大小,拖动...的图像):

Picture *pic = [[Picture alloc] initWithPicURLString:urlString];
[rootViewController.navigationController pushViewController:pic animated:YES];
[pic release];

使用NavigationController的BackButton,我总能回到上一个视图。

更多信息:

现在棘手的问题:

如果我从第二个VC切换到第三个VC,将其方向从纵向更改为横向,然后按BackButton,正常工作shouldAutorotateToInterfaceOrientation为呼叫,帧大小和起源改变......)。 但是如果我反过来做,我在横向模式,从第二个VC切换到第三个VC,将旋转到肖像来使用BackButton回到第二个VC,status-和controllerBar位于顶部,但shouldAutorotateToInterfaceOrientation 未被调用

请帮帮我。 $ H @ RKY

3 个答案:

答案 0 :(得分:1)

试试这个,它对我有用:

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self shouldAutorotateToInterfaceOrientation:[[UIApplication sharedApplication] statusBarOrientation] ];
}

答案 1 :(得分:0)

今天我有了解决问题而不知道原因的想法。 在我的第三个VC中,我刚创建了一个指向第二个视图的指针并自己调用了shouldAutorotateToInterfaceOrientation

但重点仍然是:为什么shouldAutorotateToInterfaceOrientation没有在所描述的情况下打电话?

亲切的问候。 $ H @ RKY

答案 2 :(得分:0)

shouldAutorotateToInterfaceOrientation仅在用户旋转时调用,因此当您从横向到纵向或以其他方式然后查看控制器仍然是横向时,所以这解决了问题,您必须破解代码,这意味着当您从景观中查看控制器时to portrait presentViewController示例:

ListCurrentViewController *list = [self.storyboard
   instantiateViewControllerWithIdentifier:@"ListCurrentViewController"];
               [self.navigationController presentViewController:list animated:NO completion:Nil];
               [list dismissViewControllerAnimated:NO completion:Nil];
               [self.navigationController pushViewController:list animated:YES];
ListViewController函数中的

(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation // iOS 6 autorotation fix { return UIInterfaceOrientationPortrait; }

你必须为UINavigationController创建类别

(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
    return [self.visibleViewController preferredInterfaceOrientationForPresentation];
}

我希望这个解决方案能帮到你。

相关问题