for_2012 2013-02-28 05:54 采纳率: 0%
浏览 3169
已采纳

添加两个xib文件支持iphone屏幕

请教一个关于iphone屏幕尺寸的问题,

我创建了两个xib文件(MainWindow.xibMainWindowiPhone5.xib)。这样我的屏幕就可以支持两种屏幕尺寸。

我试过在AppDelegate.m中编程,但是没有实现。

- (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都能正常运行呢?

  • 写回答

1条回答 默认 最新

  • redCoral_ 2013-02-28 06:40
    关注

    应该是这样:

    iPhone-4S屏幕:

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

    iPhone-5 屏幕:

     if ([[UIScreen mainScreen] bounds].size.height == 568)
     {
       ---- Your Code ----
     }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 切换TabTip键盘的输入法
  • ¥15 关于#网络安全#的问题:求ensp的网络安全,不要步骤要完成版文件
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥20 使用Photon PUN2解决游戏得分同步的问题
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序