Iphone 如何使我的界面方向自动旋转为纵向?

Iphone 如何使我的界面方向自动旋转为纵向?,iphone,ios,xcode,cocoa,Iphone,Ios,Xcode,Cocoa,我试图让我的一个xib文件旋转到纵向,就好像它是默认的一样 我的应用程序只支持横向方向。在plist中,我设置了“初始界面方向为横向(右主页按钮)”,因为大多数应用程序都在横向模式下运行 我在实现文件中放置的代码是: - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { // Return YES for supported orientations retur

我试图让我的一个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旋转到纵向模式?谢谢

  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);
}

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

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

您也可以稍后使用此方法强制设备的逻辑方向。注意:这是苹果的一种“官方”方法,从

iOS 6添加了3种新方法以促进界面旋转,请查看:哪个iOS版本以及如何更改viewController?您使用哪种方法获取视图。。PushView控制器或presentModalViewController@jcesar我实际上是从iOS5开始我的项目的