方向景观->肖像功能不起作用

发布于 2024-12-14 05:25:46 字数 2022 浏览 5 评论 0原文

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

self.window.rootViewController = _naviController;

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

如果我按下一个按钮,我会进入下一个 ViewController,其中包含 3 个 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 的后退按钮,我始终可以返回到上一个视图。

更多信息:

现在是棘手的问题:

如果我从第二个 VC 切换到第三个 VC,将方向从纵向更改为横向,然后按后退按钮,一切都会工作shouldAutorotateToInterfaceOrientation正在调用,帧大小和原点发生变化......)。 但是如果我反过来做,我会处于横向模式,从第二个 VC 切换到第三个 VC,旋转到纵向并且回到带有 BackButton 的 2nd VC,状态栏和控制器栏位于顶部,但 shouldAutorotateToInterfaceOrientation 未被调用

请帮我。 $h@rky

I have another orientation problem. But this one is very tricky.
My RootViewController is a normal NavigationController.

self.window.rootViewController = _naviController;

which has another ViewController inside, lets call it VC1.
VC1 has some buttons and labels. Its like an overview with folders.

If I press a button I come to the next ViewController with 3 ViewController (Page) and another bunch of buttons (like inside a folder looking at the pictures/thumbnails inside):

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

in 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];

If I now click again on a button the active Page push my third ViewController (image with resizing, dragging...):

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

With the BackButton of the NavigationController I can always come back to the previous view.

Some more informations:

  • Every ViewController supports all orientations
  • Every ViewController implements - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation with return YES;
  • Every ViewControler calls the [super init] in their init-methode
  • I already read Apple's Q&A: Why won't my UIViewController rotate with the device

Now the tricky problem:

If I switch from 2nd VC to the 3rd VC, change the orientation there from portrait to landscape and press the BackButton everything is working (shouldAutorotateToInterfaceOrientation is calling, frame size and origins changing ...).
BUT if I do it the other way around, I am in landscape mode, switch from 2nd VC to 3rd VC, rotate to portrait and come back to 2nd VC with BackButton, the status- and controllerBar are at the top but the shouldAutorotateToInterfaceOrientation wasn't called.

Please help me. $h@rky

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

无所的.畏惧 2024-12-21 05:25:46

试试这个,它对我有用:

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

Try this, it works for me:

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self shouldAutorotateToInterfaceOrientation:[[UIApplication sharedApplication] statusBarOrientation] ];
}
云朵有点甜 2024-12-21 05:25:46

今天灵机一动,在不知道原因的情况下解决了这个问题。
在我的第三个 VC 中,我刚刚创建了一个指向第二个视图的指针,并自己调用了shouldAutorotateToInterfaceOrientation。

但要点仍然是一样的:为什么 shouldAutorotateToInterfaceOrientation 在所描述的情况下不调用?

亲切的问候。 $h@rky

Today I got the idea that solved the problem without knowing the cause.
In my third VC I just created a pointer to the 2nd View and called the shouldAutorotateToInterfaceOrientation myself.

But the point is still the same: Why isn't shouldAutorotateToInterfaceOrientation not calling in the described situation?

Kind regards. $h@rky

冷清清 2024-12-21 05:25:46

shouldAutorotateToInterfaceOrientation 仅在用户旋转时调用,因此当您从横向到纵向或以其他方式查看控制器仍为横向时,因此这解决了问题,您必须破解代码,这意味着当您从横向推动视图控制器时以肖像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];
}

我希望这个解决方案对您有所帮助。

shouldAutorotateToInterfaceOrientation only called when user rotate, so when you from landscape to portrait or otherwise then view controller still landscape, so this solve problem, you have to hack code, it's mean when you push to view controller from landscape to portrait presentViewController example:

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];

in ListViewController function called:

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

and you have to create category for UINavigationController

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

I hope this solve will help you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文