启用 iPhone 界面方向
我试图让我的应用程序在设备本身旋转时旋转界面,但我无法正确执行。 我已在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
也许尝试编辑 info.plist 并在那里添加您支持的方向?
选择您的项目 -->选择您的目标 -->信息-->支持的界面方向并单击加号 4 次以支持这些方向:
希望有帮助!
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:
Hope it helps!
确保您已将
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.如果您使用标准 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.
如果您使用的是
UITabBarController
,那么您需要调用它的子视图的shouldAutoratateToInterfaceOrientation
。假设您有两个选项卡,请尝试将以下两行添加到使用
UITabViewController
的类中的方法shouldAutorotateToInterfaceOrientation
中。当然,“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 theUITabViewController
.of course the "tabBarController" must be linked to the
UITabBarController
in your XIB file via IB.Thanks,