在 UINavigationController 中转换为纵向旋转

发布于 2024-09-07 06:07:53 字数 635 浏览 1 评论 0原文

我有一种情况,需要将仅纵向模式视图推送到导航控制器中,该导航控制器将横向模式视图作为其当前视图。

虽然我已经重新实现了

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation   {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

,但它仍然在横向模式下推动视图。我也尝试过以下方法,但即使这样也不起作用。

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:YES];
}

我尝试查看其他相关问题,但没有找到任何东西。

知道我该如何解决这个问题吗?

谢谢!

I have a case where a portrait only mode view needs to be pushed into a navigation controller which has a landscape mode view as its current view.

Although I have reimplemented

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation   {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

but it is still pushing the view in landscape mode. I have also tried the following way, but even this is not working.

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:YES];
}

I tried looking into other related questions but did not find anything.

Any idea how I can solve this?

Thanks!

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

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

发布评论

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

评论(1

久夏青 2024-09-14 06:07:53

最好的选择是只使用模态视图控制器,它会强制视图处于纵向,无论设备方向如何。

如果您想在其周围包装一个导航控制器以保持样式一致,请查看 Apple 的 核心数据配方示例,了解当您添加新配方时它们如何执行此操作。

Your best bet is to just use a modal view controller instead which forces the view to be in portrait regardless of device orientation.

If you want to wrap a navigation controller around it to keep styling consistent, look at Apple's Core Data Recipes example for how they do this when you add a new recipe.

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