[英]Different layout for iPad and iPhone
I am making an iphone app at the moment. 我现在正在制作一款iphone应用程序。 But in the future this app should also be available for iPad.
但在未来,这个应用程序也应该可用于iPad。 At the moment I am using storyboards, because it's quite easy to make it also available for iPad in this way.
目前我正在使用故事板,因为以这种方式使iPad也可以很容易地使用它。
My question is now, some views like a long profile form, you put it inside a scrollview. 我现在的问题是,有些视图就像一个长篇文章,你把它放在一个滚动视图中。 But you cannot build scrollviews layouts inside a storyboard, so I created them in code.
但是你无法在故事板中构建scrollviews布局,所以我在代码中创建了它们。 But what should I do if I want this views layout also available for iPad?
但是,如果我希望这个视图布局也适用于iPad,我该怎么办?
Should I rewrite the layout code for iPad and then do some device detection? 我应该重写iPad的布局代码,然后进行一些设备检测吗? What is the best practice?
什么是最佳做法?
I think better detect hardware and write different layout code. 我认为更好地检测硬件并编写不同的布局代码。
You can use Apple's Macro: 你可以使用Apple的宏:
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
// Write your layout code for iPad there
}
else
{
// Write your layout code for iPhone/iPod there
}
Below will be useful for you. 以下将对您有用。
#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!");
}
Cheers! 干杯!
The solution was rather simple. 解决方案相当简单。 First I thought you cannot create scrollviews inside a storyboard.
首先,我认为你无法在故事板中创建滚动视图。 But this is possible!
但这是可能的! You can find how to do it over here .
你可以在这里找到如何做到这一点 。
So now the solution is that you create another storyboard specifically for iPad! 所以现在的解决方案是你专门为iPad制作另一个故事板!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.