强制旋转 TabbarController 中 NavigationController 中的 UIViewController

发布于 2024-12-17 21:01:36 字数 434 浏览 3 评论 0原文

我的视图层次结构是这样设置的。

UITabBarController
    |
    UINavigationController
    |  |
    |  UIViewController
    |
    UINavigationController
       |
       UIViewController

问题是,我有一个仅以纵向显示的 ViewController,一旦我将设备转向横向,另一个 ViewController 就会被推到顶部,到目前为止,它正在按预期工作。

我现在想要的是,一旦我按下新弹出的 ViewController 上的后退按钮,旧的 ViewController 就会被强制为纵向,即使设备仍处于横向状态。
我已经尝试过使用过渡,但是其他视图都被搞砸了,并且无法正确识别那里的方向,从而导致混乱的移位视图。

I've got my View hierarchy set up like this.

UITabBarController
    |
    UINavigationController
    |  |
    |  UIViewController
    |
    UINavigationController
       |
       UIViewController

The thing is that I have a ViewController that is only shown in Portrait, as soon as I turn the device to landscape another ViewController is being pushed on top, that is working as intended so far.

What I want now is that as soon as I push the back button on the newly popped ViewController that the old ViewController is being forced to Portrait, even though the Device is still in Landscape.
I have tried it with transitions, but then the other views are getting screwed and don't properly recognize there orientation anymore leading to a mess of displaced views.

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

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

发布评论

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

评论(3

我偏爱纯白色 2024-12-24 21:01:36

唯一对我有用的是

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

在我的 ViewController 中使用并用 presentModalViewController 呈现它。
这迫使视图保持横向。
不完全是我想要的,但它成功了。

The only thing that worked for me was using

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

in my ViewController and presenting it with presentModalViewController.
This forces the View to stay in landscape.
Not exactly what I wanted, but it worked out.

阳光下慵懒的猫 2024-12-24 21:01:36

尝试将其添加到您的原始视图控制器:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    if (UIInterfaceOrientationIsPortrait(interfaceOrientation)) return YES;
    return NO;
}

这应该强制它仅以纵向显示。

Try adding this to your original view controller:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    if (UIInterfaceOrientationIsPortrait(interfaceOrientation)) return YES;
    return NO;
}

This should force it to only display in portrait orientation.

栖竹 2024-12-24 21:01:36

下面的代码将强制视图进入横向模式,但前提是父视图控制器支持横向模式。

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

如果您想要强制进入横向模式的视图的父视图控制器仅为纵向,则必须创建一个新的导航控制器。最简单的方法就是在模态视图中呈现强制横向视图控制器。所以使用presentModalViewController而不是pushViewController。

The code below will force the view into landscape mode, but only if the parent view controller supports landscape mode.

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

If the parent view controller of the view you want to force into landscape mode is portrait only, you'll have to create a new new navigation controller. The easiest way to do that is just presenting the forced-landscape view controller in a modal view. So use presentModalViewController instead of pushViewController.

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