修复视图控制器的方向

发布于 2024-09-18 15:30:08 字数 203 浏览 7 评论 0原文

我的 RootViewController 中有一个按钮...... 当我单击此按钮时,它将导航到其他视图控制器。 但我希望当我单击按钮时 otherViewController 的方向应该是横向 &当我从这个页面(otherViewController)返回时,我应该再次获得纵向模式。

非常感谢您的帮助。 请帮助我,我是 iPhone 新手,所以无法处理这个问题。

I have a button in my RootViewController ....
when i click on this button it will navigate to some otherViewController.
but i want that when i click on the Button otherViewController's Orientation should be Landscape
& when i back from this page(otherViewController) i should got again Portrait mode.

lots of Thanks for any help.
Plz help me i m new in Iphone so can't able to handle this.

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

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

发布评论

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

评论(4

乱了心跳 2024-09-25 15:30:08

请注意,iOS 6 中的 shouldAutorotateToInterfaceOrientation已弃用。相反,您应该使用 supportedInterfaceOrientations 并返回 UIInterfaceOrientationMask

例如:

- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskLandscape;
}

以下是您可能返回的所有 UIInterfaceOrientationMask 选项:

UIInterfaceOrientationMaskAll
UIInterfaceOrientationMaskAllButUpsideDown
UIInterfaceOrientationMaskLandscape
UIInterfaceOrientationMaskLandscapeLeft
UIInterfaceOrientationMaskLandscapeRight
UIInterfaceOrientationMaskPortrait
UIInterfaceOrientationMaskPortraitUpsideDown

您还应该考虑 preferredInterfaceOrientationForPresentation

Note in iOS 6 shouldAutorotateToInterfaceOrientation is deprecated. Instead you should use supportedInterfaceOrientations and return a UIInterfaceOrientationMask.

So for example:

- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskLandscape;
}

Here are all the UIInterfaceOrientationMask options you might return:

UIInterfaceOrientationMaskAll
UIInterfaceOrientationMaskAllButUpsideDown
UIInterfaceOrientationMaskLandscape
UIInterfaceOrientationMaskLandscapeLeft
UIInterfaceOrientationMaskLandscapeRight
UIInterfaceOrientationMaskPortrait
UIInterfaceOrientationMaskPortraitUpsideDown

You should also consider the preferredInterfaceOrientationForPresentation.

老子叫无熙 2024-09-25 15:30:08

一般来说,当用户旋转设备时,方向只能从纵向更改为横向(反之亦然)。

但是,如果您希望 RootViewController 始终以纵向方式呈现其视图,而 OtherViewController 始终以横向方式呈现其视图,那就很简单了。

在 RootViewController 的 .h 中:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

在 OtherViewController 的 .h 中:

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

虽然这可能会更好,因为它允许横向左旋转和横向右旋转:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}

In general, orientation should only change from portrait to landscape (or vice versa) when the user rotates the device.

However, if you want your RootViewController to always present its view in portrait and your OtherViewController to always present itvs view in landscape, that's easy enough.

In your RootViewController's .h:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

In your OtherViewController's .h:

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

Although this would probably be better as it would allow both landscape-left and landscape-right rotations:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
卸妝后依然美 2024-09-25 15:30:08

我知道可以做到这一点的唯一方法是以模态方式呈现 otherViewController 。

在这里查看我的答案: UIViewController 加载旋转到横向但仅支持纵向

The only way I am aware this can be done is by presenting otherViewController modally.

See my answer here: UIViewController loads rotated to landscape but only supports portrait

诠释孤独 2024-09-25 15:30:08

也许有帮助。

在新视图控制器的 viewWillAppear 中添加

[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscape]

并在根 viewController 的 viewWillAppear 中添加

[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationPortrait];

它会导致警告,但它可以工作。

Maybe it helps.

in viewWillAppear of your new view controller add

[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscape]

and in viewWillAppear of your root viewController add

[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationPortrait];

It will cause warning but it works.

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