所以我目前正在创建一个包含六个视图的应用程序,每个视图专用于设备类型和方向的组合。如果您不明白我的意思,我会标记所有六种组合:
我知道解决所有这些麻烦似乎有点傻,但在这种情况下有点需要。无论如何,我一直试图尝试将Programming Guide的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;
}
}
每个视图的Interface Builder设置
我也收到Expected identifier
的一些错误:
有些人可以帮助我,或者至少指出我正确的方向吗?
更新1
每当我启动应用程序时,我都会看到黑屏。这是我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];
}
}
答案 0 :(得分:1)
您与Expected Identifier
相关的错误是因为您的父母错了。你的if
条件应该是(我在其他几个条件中也会看到相同的错误):
else if (((deviceOrientation == UIInterfaceOrientationLandscapeLeft) || (deviceOrientation == UIInterfaceOrientationLandscapeRight)) && [UIScreen mainScreen].bounds.size.height == 480.0)