0

我试图让我的一个 xib 文件旋转到纵向,就好像它首先是默认设置一样。

我让我的应用程序只支持横向。在 plist 中,我将“初始界面方向设置为横向(右主页按钮)”,因为大多数应用程序在横向模式下运行。

我在我的实现文件中放置的代码是:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations

return interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight;

}

现在,当更改为需要界面处于纵向模式的视图控制器时,我已将此代码放在 xib 文件的实现文件中,以使其进入纵向模式并单独支持纵向模式。因此,即使设备处于横向模式,它仍然会以纵向模式运行视图。

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations

return interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortrait;

}

虽然这似乎不起作用。它只是保持横向模式并挤压图像视图和我放置在 xib 文件中的其他对象。如何让 xib 旋转到纵向模式?谢谢。

4

2 回答 2

0

我的经验表明,在 plist 文件中设置 UIInterfaceOrientation 没有任何效果。另一方面,您可以通过设置在启动时强制一个方向(例如横向):

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft];
    // your stuff
{

您稍后也可以使用此方法来强制设备的逻辑方向。注意:截至本文档,这是 Apple 的“官方”方法

于 2012-10-23T12:28:16.847 回答
0
  change your Xib in Landscape Mode only and then click on your project file then target   then select only Landscape mode or Portrait Mode(left/right or both) 
  then go to this method 
I am using Landscape Mode.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
  // Return YES for supported orientations
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}

在此处输入图像描述

于 2012-10-03T15:18:14.250 回答