0

我目前正在创建一个具有六个视图的应用程序,每个视图都专用于设备类型方向的组合。如果您不明白我的意思,我将标记所有六种组合:

  • iPhone4_(320x480) & 肖像
  • iPhone4_(320x480) & 横向
  • iPhone5_(320x568) & 肖像
  • iPhone5_(320x568) & 横向
  • iPad_(768x1024) & 肖像
  • iPad_(768x1024) & 横向

我知道经历所有这些麻烦似乎有点愚蠢,但在这种情况下这是必需的。无论如何,我一直在尝试将 Apple 的编程指南中的解决方案与TheAppCodeBlog上的在线教程中给出的方法结合起来。

ViewController.m-->ViewDidLoad方法

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:@"UIDeviceOrientationDidChangeNotification" object:nil];

ViewController.m-->orientationChanged方法

- (void) orientationChanged:(NSNotification *)object
{
    UIDeviceOrientation deviceOrientation = [[object object] orientation];
    if (deviceOrientation == UIInterfaceOrientationPortrait && [UIScreen mainScreen].bounds.size.height == 480.0)
    {
        self.view = self.portrait4View;
    }
    else if ((deviceOrientation == UIInterfaceOrientationLandscapeLeft) || (deviceOrientation == UIInterfaceOrientationLandscapeRight)) && [UIScreen mainScreen].bounds.size.height == 480.0)
    {
        self.view = self.landscape4View;
    }
    else if (deviceOrientation == UIInterfaceOrientationPortrait && [UIScreen mainScreen].bounds.size.height == 568.0)
    {
        self.view = self.portrait5View;
    }
    else if ((deviceOrientation == UIInterfaceOrientationLandscapeLeft) || (deviceOrientation == UIInterfaceOrientationLandscapeRight)) && [UIScreen mainScreen].bounds.size.height == 568.0)
    {
        self.view = self.landscape5View;
    }
    else if (deviceOrientation == UIInterfaceOrientationPortrait && [UIScreen mainScreen].bounds.size.height == 1024.0)
    {
        self.view = self.portraitPadView;
    }
    else
    {
        self.view = self.landscapePadView;
    }

}

每个视图的界面生成器设置:

界面生成器

我也收到一些错误Expected identifier

迷你橱窗

更新

每当我启动应用程序时,我都会得到一个黑屏。这是我的AppDelegate.m样子:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone && [UIScreen mainScreen].bounds.size.height == 568.0) {
        self.viewController = [[ViewController alloc] initWithNibName:@"ViewController_Portrait5" bundle:nil];
    }
    
    else if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone && [UIScreen mainScreen].bounds.size.height == 480.0) {
        self.viewController = [[ViewController alloc] initWithNibName:@"ViewController_Portrait4" bundle:nil];
    }

    else {
        self.viewController = [[ViewController alloc] initWithNibName:@"ViewController_PortraitPad" bundle:nil];
    }
}
4

1 回答 1

1

你的错误Expected Identifier是因为你的括号是错误的。您的if情况应该是(我在其他几个情况下也看到相同的错误):

else if (((deviceOrientation == UIInterfaceOrientationLandscapeLeft) || (deviceOrientation == UIInterfaceOrientationLandscapeRight)) && [UIScreen mainScreen].bounds.size.height == 480.0)
于 2012-12-07T23:58:43.550 回答