1

我遇到了 iPhone 5 屏幕尺寸的问题。我创建了两个 xib 文件MainWindow.xibMainWindowiPhone5.xib),以便我的应用程序支持两种屏幕尺寸。

我一直在尝试在我的 AppDelegate.m 上对其进行编码,但它不起作用。

这是我的 AppDelegate 代码:

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone){
    UIStoryboard *storyBoard;

    CGSize result = [[UIScreen mainScreen] bounds].size;
    CGFloat scale = [UIScreen mainScreen].scale;
    result = CGSizeMake(result.width * scale, result.height * scale);

    if(result.height == 1136){
        storyBoard = [UIStoryboard storyboardWithName:@"MainWindowiPhone5" bundle:nil];
        UIViewController *tabBarController = [storyBoard instantiateInitialViewController];
        [self.window.rootViewController = self.tabBarController];
    }
}

return YES;



self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];



// Override point for customization after application launch.
// Set the tab bar controller as the window's root view controller and display.
self.window.rootViewController = self.tabBarController;
tabBarController.moreNavigationController.navigationBar.tintColor = [UIColor blackColor];
[self.window makeKeyAndVisible];
return YES;

}

如何让两个 xib 都在我的代码上工作?

请帮忙。谢谢。

4

2 回答 2

2

条件应该是::

对于 iPhone-4S 或更旧的屏幕:

 if ([[UIScreen mainScreen] bounds].size.height == 480)
 {
   ---- Your Code ----
 }

iPhone-5 屏幕:

 if ([[UIScreen mainScreen] bounds].size.height == 568)
 {
   ---- Your Code ----
 }

希望...它可能对您有所帮助。
谢谢。

于 2013-02-25T04:07:54.193 回答
0

在初始化中添加此代码:

if([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone){
     if([UIScreen mainScreen].bounds.size.height == 568.0)){
             //move to your iphone5 storyboard
             [UIStoryboard storyboardWithName:(NSString *) bundle (NSBundle *)];
  }
     else{
             //move to your iphone4s storyboard
             [UIStoryboard storyboardWithName:(NSString *) bundle (NSBundle *)];
  }
}
于 2013-02-25T04:28:30.163 回答