【发布时间】:2012-12-07 23:54:56
【问题描述】:
我目前正在创建一个包含六个视图的应用程序,每个视图专用于设备类型和方向的组合。如果您不明白我的意思,我将标记所有六种组合:
- iPhone4_(320x480) 和肖像
- iPhone4_(320x480) 和横向
- iPhone5_(320x568) 和肖像
- iPhone5_(320x568) 和横向
- iPad_(768x1024) 和肖像
- iPad_(768x1024) 和横向
我知道经历所有这些麻烦似乎有点愚蠢,但在这种情况下这是必需的。无论如何,我一直在尝试将来自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;
}
}
每个视图的界面生成器设置:
我还收到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];
}
}
【问题讨论】:
标签: iphone ios ipad optimization screen-orientation