我有一个用旧版 Xcode 编写的应用程序。现在我正在使用 Xcode 4.6.1。这是我从公司外部开发的另一位开发人员那里继承的应用程序。
这个应用程序的一个问题是它的界面。它应该默认为 LandscapeLeft(这是在 pList 文件中设置的值)。该应用会忽略此指令,而是默认为纵向模式。
我需要做些什么来强制代码接受这个值吗?我对 iOS/Objective-C 比较陌生。代码编译并运行,只是界面没有按照我的要求进行。
因为这是一款仅限 iPad 的应用程序,所以要容易一些。
编辑 我已经尝试将以下代码添加到我的一个有问题的 viewController 中,但它没有被接受。关于如何将这种观点强制景观的任何想法? (IDE里有没有设置-好像Xcode以前有orientation属性,但是我在4.6.1找不到了)
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Overriden to allow any orientation.
return ((interfaceOrientation==UIInterfaceOrientationMaskLandscapeLeft) || (interfaceOrientation == UIInterfaceOrientationMaskLandscapeRight));
}
- (NSUInteger) supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscapeLeft;
}
- (NSInteger) supportedInterfaceOrientationsForWindow
{
return UIInterfaceOrientationMaskLandscape;
}
- (BOOL) shouldAutoRotate
{
return YES;
}
最佳答案
希望对您有所帮助。
在 AppDelegate.m
类
强制在横向模式下完全运行应用程序:
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
return UIInterfaceOrientationMaskLandscape;
}
强制在纵向模式下完全运行应用程序:
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
return UIInterfaceOrientationMaskPortrait;
}
关于ios - 默认应用方向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16089659/