Objective c 强制iOS应用程序以横向模式启动

Objective c 强制iOS应用程序以横向模式启动,objective-c,ios5,xcode4.2,Objective C,Ios5,Xcode4.2,我正在为iOS 5开发一个应用程序,它必须在横向模式下运行。我的问题是我不能让它一开始翻转 我尝试将“初始界面方向”设置为“横向(右主按钮)” 并将以下方法添加到“我的视图控制器”: - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { // Return YES for supported orientations return (interfaceOrient

我正在为iOS 5开发一个应用程序,它必须在横向模式下运行。我的问题是我不能让它一开始翻转

我尝试将“初始界面方向”设置为“横向(右主按钮)” 并将以下方法添加到“我的视图控制器”:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
我可以把我的头绕在它应该如何工作上。(我找到了密码)

我还想知道如何使用Xcode 4.2项目设置中提供的“支持的设备定向”,它似乎没有任何作用

我一直在网站上四处寻找,没有找到一个能解决我问题的例子


谢谢。

我认为如果您在项目plist中了解支持的界面方向,它将起作用。只需添加一个名为“Supported interface orientations”的新行,将其设置为数组类型,并为您想要的每个landsape视图添加2项。没有测试过这一点,只是快速猜测一下

在应用程序的Info.plist文件中,添加
UIInterfaceOrientation
键并将其值设置为 景观模式。景观 方向,可以设置值 这把钥匙
ui接口方向和scapeleft
UIInterfaceOrientationAndscapeRight

以横向模式布置视图,并确保其自动调整大小选项设置正确


重写视图控制器的
shouldAutorotateToInterfaceOrientation:
方法,并仅对 所需的景观方向和无
用于纵向方向。

当您在XCode中单击项目名称并在“目标”下选择目标时,在“摘要”选项卡下,将显示支持的设备方向设置的可视化表示。这就是我如何做到的。

试试这个。这将帮助您,在您的视图中编写代码

[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight];

在appDelegate中使用以下命令

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

    [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight];
还可以在中设置所需的方向

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

//Here are some iOS6 apis, used to handle orientations.
- (BOOL)shouldAutorotate NS_AVAILABLE_IOS(6_0) 
- (NSUInteger)supportedInterfaceOrientations - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation

非常感谢。我照你说的做了。我有多个子视图,发现我必须在所有控制器上重写该方法,然后才能使其工作。如果在your info.p中,您将UIInterfaceOrientation和景观放在其他景观的正上方,则可以在Landscape上启动应用程序shouldAutorotateTointerFaceOrientation:不调用help me itsappreciated@JigPatel使用一些ios6
-(BOOL)中的这些新方法应该自动旋转NS\u可用的IOS(6\u 0)-(NSInteger)支持的接口方向-(UIInterfaceOrientation)首选用于演示的接口方向