ios - 默认应用方向

标签 ios objective-c cocoa-touch orientation

我有一个用旧版 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/

相关文章:

ios - 如何在 Xcode 的项目目录中打开 Playground?

iphone - UILocalNotification 执行操作

iphone - 如何正确定义结构

iphone - 无法设置 View Controller 的委托(delegate)

iphone - UIWebView - 如何获取访问过的链接以显示为访问过?

ios - 以编程方式将 admob View 添加到 UITableView 的顶部或底部?

android - 如何创建跨平台 Xamarin 移动应用程序项目?

ios - 如何在 swift 5 xcode 10 中创建在多个 View 中使用的单例 View

ios - CJSON反序列化错误

objective-c - 如何设置uiclearcolor的alpha?