iPad和iPhone的不同布局

时间:2012-12-26 14:42:48

标签: iphone objective-c ios ipad storyboard

我正在制作一款iphone应用程序。但在未来,这个应用程序也应该可用于iPad。目前我正在使用故事板,因为以这种方式使iPad也可以很容易地使用它。

现在我的问题是,有些视图就像一个长篇文章,你把它放在一个滚动视图中。但是你无法在故事板中构建scrollviews布局,所以我在代码中创建了它们。但是,如果我希望这个视图布局也适用于iPad,我该怎么办?

我应该重写iPad的布局代码,然后进行一些设备检测吗? 什么是最佳做法?

3 个答案:

答案 0 :(得分:2)

我认为更好地检测硬件并编写不同的布局代码 您可以使用Apple的Macro:

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
     // Write your layout code for iPad there
}
else
{
     // Write your layout code for iPhone/iPod there
}

答案 1 :(得分:0)

下面对您有用。

#define IS_IPHONE ( [[[UIDevice currentDevice] model] isEqualToString:@"iPhone"] )
#define IS_IPOD   ( [[[UIDevice currentDevice] model] isEqualToString:@"iPod touch"] )
#define IS_IPAD   ( [[[UIDevice currentDevice] model] isEqualToString:@"iPad"] )
#define IS_IPHONE_5_SCREEN [[UIScreen mainScreen] bounds].size.height >= 568.0f && [[UIScreen mainScreen] bounds].size.height < 1024.0f
#define IS_IPHONE_4_SCREEN [[UIScreen mainScreen] bounds].size.height >= 480.0f && [[UIScreen mainScreen] bounds].size.height < 568.0f


if(IS_IPHONE_5_SCREEN)
{
    if(IS_IPHONE)
        NSLog(@"Hey, this is an iPhone 5 screen!");
    else if(IS_IPOD)
        NSLog(@"Hey, this is an iPod 5 screen!");
    else
        NSLog(@"Hey, this is a simulator screen with iPhone 5 screen height!");
}
else if(IS_IPHONE_4_SCREEN)
{
    if(IS_IPHONE)
        NSLog(@"Hey, this is a lower iPhone screen than 5!");
    else if(IS_IPOD)
        NSLog(@"Hey, this is a lower iPod screen than 5!");
    else
        NSLog(@"Hey, this is a lower simulator screen than 5!");
}
else if(IS_IPAD){
    NSLog(@"Hey, this is an iPad screen!");
}
else{
    NSLog(@"Hey, this is an ipad simulator screen!");
}

干杯!

答案 2 :(得分:0)

解决方案相当简单。 首先,我认为你无法在故事板中创建滚动视图。但这是可能的! 您可以在here上找到如何执行此操作。

所以现在的解决方案是你专门为iPad创建另一个故事板!