iPad初步定位

时间:2011-05-05 20:25:25

标签: ipad uiviewcontroller orientation uisplitviewcontroller landscape

我很难让我的应用程序正确支持所有方向。 问题在于启动。我已经完成了以下步骤:

  1. 已添加:

    <key>UISupportedInterfaceOrientations</key>
    <array>
        <string>UIInterfaceOrientationPortraitUpsideDown</string>
        <string>UIInterfaceOrientationLandscapeLeft</string>
        <string>UIInterfaceOrientationLandscapeRight</string>
        <string>UIInterfaceOrientationPortrait</string>
    </array>
    
  2. 确保我的所有视图控制器始终在shouldAutorotateToInterfaceOrientation中返回YES
  3. 添加了所有默认*图片
  4. 当处于横向状态时 - 应用程序开始显示正确的默认图像,但实际应用程序将以纵向方式启动。不会调用willRotate ...和shouldAutorotate ..方法。

    我甚至尝试过调配方法(来自Wordpress):

    + (void)youWillAutorotateOrYouWillDieMrBond {
        NSLog(@"youWillAutorotateOrYouWillDieMrBond");
        Swizzle([NSClassFromString(@"UISplitViewController") class], @selector(shouldAutorotateToInterfaceOrientation:), @selector(MyShouldAutorotateToInterfaceOrientation:), NULL);
        Swizzle([NSClassFromString(@"UIViewController") class], @selector(shouldAutorotateToInterfaceOrientation:), @selector(MyShouldAutorotateToInterfaceOrientation:), NULL);
    }
    
    - (BOOL)MyShouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
        NSLog(@"MyShouldAutorotateToInterfaceOrientation (%@)", self);
        return(YES);
    }
    

    也没有运气。无论我做什么 - 如果设备处于横向状态,应用程序将以肖像方式启动。

    我已阅读相应的Apple文档 - 他们声明应用程序始终以纵向开始,但如果VC支持方向,则自行轮换。所以我似乎正在尽我所能......

    在这里真的没有想法,会感激任何见解。

4 个答案:

答案 0 :(得分:4)

好的,感谢所有帮助过的人,但这不是提议的解决方案之一: 好像我偶然发现了一些iPAD错误。

解决方案很简单:

主视图由于某种原因没有收到任何事件,这就是问题所在。我做的是将UIViewController包装在UINavigationController中并将其设置为Master。然后导航控制器DID接收事件并传递它们。问题解决了!

答案 1 :(得分:0)

可能是你的笔尖设置错误的问题。您可以将笔尖的起始位置更改为横向或肖像。我发现这比使用视图控制器更容易。

要执行此操作,请转到“界面”构建器,选择视图。在“视图属性”窗口中选择最左侧的选项卡,然后将方向更改为横向。

答案 2 :(得分:0)

首先,检查你的info.plist中是否有所有四个UISupportedInterfaceOrientations

接下来,检查您是否在应用委托的applicationDidFinishLaunchingWithOptions中将拆分视图添加到应用窗口(例如[self.window addSubview:splitViewController.view];),而不是更晚,这可能会导致此问题。

或者,UIWindow仅可靠地将旋转传递给添加到窗口的第一个视图的视图控制器。根据您执行拆分视图控制器的方式,这可能是问题所在。确保您需要正确旋转的任何视图都在子视图层次结构中,这是第一个添加到窗口中的视图,这样它的视图控制器就可以正确地传递旋转事件。

希望有所帮助!

答案 3 :(得分:0)

如果无法解决问题,请尝试将此信息添加到Info.plist文件中。它适用于我的通用应用程序:

<key>UISupportedInterfaceOrientations~ipad</key>
<array>
    <string>UIInterfaceOrientationPortrait</string>
    <string>UIInterfaceOrientationPortraitUpsideDown</string>
    <string>UIInterfaceOrientationLandscapeLeft</string>
    <string>UIInterfaceOrientationLandscapeRight</string>
</array>

这里的区别在于您通过~ipad代码段强制这些属性与iPad相关。

如果您想在启动应用时强制定位,则应尝试更新添加此方法的applicationDidFinishLaunching:方法,以强制更改方向的通知:

UIDevice *device = [UIDevice currentDevice];
[device beginGeneratingDeviceOrientationNotifications];

希望这有帮助。

如果这不起作用,则可能是与应用程序初始化相关的问题,即您创建UISplitViewController并向其添加侧面和细节控制器的方式。在这种情况下,请过去那段代码。