启用 iPhone 界面方向

发布于 2024-10-10 01:54:43 字数 514 浏览 0 评论 0原文

我试图让我的应用程序在设备本身旋转时旋转界面,但我无法正确执行。 我已在 plist 信息文件中添加了受支持的接口,并为 shouldRotateToInterfaceOrientation 返回了 yes。

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {  
    if (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight) {  
        return YES;  
    } else {  
        return NO;  
    }  
} 

这就是轮换的实现方式吗?
请帮忙!

I'm trying to get my application to rotate the interface when the device itself is rotated, but I can't get it right.
I have added the supported interfaces in the plist info file and returned yes for the shouldRotateToInterfaceOrientation.

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {  
    if (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight) {  
        return YES;  
    } else {  
        return NO;  
    }  
} 

Is this how rotation is implemented?
Please help!

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

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

发布评论

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

评论(4

何处潇湘 2024-10-17 01:54:43

也许尝试编辑 info.plist 并在那里添加您支持的方向?

选择您的项目 -->选择您的目标 -->信息-->支持的界面方向并单击加号 4 次以支持这些方向:

Item 0   Landscape (left home button)
Item 1   Landscape (right home button)
Item 2   Portrait (top home button)
Item 3   Portrait (bottom home button)

希望有帮助!

Maybe try editing the info.plist and also add your supported orientations there?

Select your project --> Select your target --> Info --> Supported interface orientations and click on the plus sign 4 times to support these orientations:

Item 0   Landscape (left home button)
Item 1   Landscape (right home button)
Item 2   Portrait (top home button)
Item 3   Portrait (bottom home button)

Hope it helps!

樱&纷飞 2024-10-17 01:54:43

确保您已将 shouldRotateToInterfaceOrientation 添加到要支持不同方向的视图控制器。它不会进入应用程序委托。

Make sure you've added shouldRotateToInterfaceOrientation to the view controllers that you want to support different orientations. It doesn't go in the app delegate.

美胚控场 2024-10-17 01:54:43

如果您使用标准 UI 元素,那么支持方向是很简单的,因此,假设情况确实如此,那么您就走在正确的轨道上。

如果您使用 UITabController,所有视图必须支持相同的方向,否则它默认为最小值(例如纵向),我相信。

另外,如果您的视图使用 NIB,请确保在 Interface Builder 中配置视图时选中“自动调整子视图大小”。

Supporting orientation is straight-forward if you're using standard UI elements so, assuming that's the case, you're on the right track.

If you're using a UITabController, all the views must support the same orientations, otherwise it defaults to the minimum (e.g. Portrait), I believe.

Also, if you're using NIBs for your views, make sure you have 'Autoresize subviews' checked when configuring the view in Interface Builder.

苄①跕圉湢 2024-10-17 01:54:43

如果您使用的是UITabBarController,那么您需要调用它的子视图的shouldAutoratateToInterfaceOrientation

假设您有两个选项卡,请尝试将以下两行添加到使用 UITabViewController 的类中的方法 shouldAutorotateToInterfaceOrientation 中。

[[tabBarController.viewControllers objectAtIndex:0] shouldAutorotateToInterfaceOrientation:interfaceOrientation];
[[tabBarController.viewControllers objectAtIndex:1] shouldAutorotateToInterfaceOrientation:interfaceOrientation];

当然,“tabBarController”必须通过 IB 链接到 XIB 文件中的 UITabBarController

谢谢,

if you are using UITabBarController, then you'll need to call it's subviews' shouldAutoratateToInterfaceOrientation.

suppose you have two tabs, please try to add the following two lines to method shouldAutorotateToInterfaceOrientation in the class that uses the UITabViewController.

[[tabBarController.viewControllers objectAtIndex:0] shouldAutorotateToInterfaceOrientation:interfaceOrientation];
[[tabBarController.viewControllers objectAtIndex:1] shouldAutorotateToInterfaceOrientation:interfaceOrientation];

of course the "tabBarController" must be linked to the UITabBarController in your XIB file via IB.

Thanks,

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