iPhone 5视图布局的帮助
我使用的视图需要允许与iPhone5屏幕匹配,但是我似乎无法获得正确的布局,我已经尝试过了iPhone 5视图布局的帮助,iphone,ios,xcode,ipad,Iphone,Ios,Xcode,Ipad,我使用的视图需要允许与iPhone5屏幕匹配,但是我似乎无法获得正确的布局,我已经尝试过了 if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone ) { if (IS_IPHONE5) { NSLog(@"iPhone 5"); [SelectionPhotoOptionView setFrame:CGRectMake
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone )
{
if (IS_IPHONE5) {
NSLog(@"iPhone 5");
[SelectionPhotoOptionView setFrame:CGRectMake(470, 0, 640, 568)];
[SelectionButView setFrame:CGRectMake(0, 0, 640, 568)];
[imageViewSelection setFrame:CGRectMake(0, 0, 640, 568)];
[imageViewPhotoOption setFrame:CGRectMake(-470, 0, 640, 568)];
ButtonYpos=612;
} else {
NSLog(@"iPhone 4 and Lower");
[SelectionPhotoOptionView setFrame:CGRectMake(470, 0, 320, 480)];
[SelectionButView setFrame:CGRectMake(0, 0, 320, 480)];
[imageViewSelection setFrame:CGRectMake(0, 0, 320, 480)];
[imageViewPhotoOption setFrame:CGRectMake(-470, 0, 320, 480)];
ButtonYpos=412;
}
上面的部分是错误的,iPhone5的布局不正确,我想知道是否有人能帮我提供一个更简洁的代码示例来使用
谢谢,
Chris通过执行以下操作检查屏幕高度:
screenRect = [UIScreen mainScreen].bounds;
screenHeight = screenRect.size.height;
if( screenHeight == 568){
NSLog(@"iPhone 5");
}
else NSLog (@"iPhone 4s or below");
当根据屏幕大小设置帧时,如果有导航栏(默认值约为40px)和状态栏(我认为是10px),请确保在导航栏中进行计算
此外,宽度仍为320px,操作系统将自动调整视网膜显示。您可以使用以下命令检查设备分辨率是iPhone 5(4英寸)还是更低分辨率(3.5英寸) 然后,您可以通过将代码替换为以下代码来设置帧:
if (IS_IPHONE)
{
[SelectionPhotoOptionView setFrame:CGRectMake(470, 0, 320, IS_IPHONE_5?568:480)];
[SelectionButView setFrame:CGRectMake(0, 0, 320, IS_IPHONE_5?568:480)];
[imageViewSelection setFrame:CGRectMake(0, 0, 320, IS_IPHONE_5?568:480)];
[imageViewPhotoOption setFrame:CGRectMake(-470, 0, 320, IS_IPHONE_5?568:480)];
ButtonYpos=IS_IPHONE_5?612:412;
}
注意:对于iPhone5,您给出的宽度为640,而对于iPhone4,则为320。而两个设备的宽度相同。所以我在两种情况下都改变了宽度320
这对你有用。只需为iphone4和iPhone5使用两个.xib即可。它很简单,无需设置框架,只需按正确的视图/xib即可。 像 //设备兼容性
#define g_IS_IPHONE ( [[[UIDevice currentDevice] model] isEqualToString:@"iPhone"] )
#define g_IS_IPOD ( [[[UIDevice currentDevice] model] isEqualToString:@"iPod touch"] )
#define g_IS_IPAD ( [[[UIDevice currentDevice] model] isEqualToString:@"iPad"] )
#define g_IS_IPHONE_5_SCREEN [[UIScreen mainScreen] bounds].size.height >= 568.0f && [[UIScreen mainScreen] bounds].size.height < 1024.0f
#define g_IS_IPHONE_4_SCREEN [[UIScreen mainScreen] bounds].size.height >= 480.0f && [[UIScreen mainScreen] bounds].size.height < 568.0f
#define g_IS_IPHONE ( [[[UIDevice currentDevice] model] isEqualToString:@"iPhone"] )
#define g_IS_IPOD ( [[[UIDevice currentDevice] model] isEqualToString:@"iPod touch"] )
#define g_IS_IPAD ( [[[UIDevice currentDevice] model] isEqualToString:@"iPad"] )
#define g_IS_IPHONE_5_SCREEN [[UIScreen mainScreen] bounds].size.height >= 568.0f && [[UIScreen mainScreen] bounds].size.height < 1024.0f
#define g_IS_IPHONE_4_SCREEN [[UIScreen mainScreen] bounds].size.height >= 480.0f && [[UIScreen mainScreen] bounds].size.height < 568.0f
if (g_IS_IPHONE_4_SCREEN) {
styleDetailObj =[[StyleDetailViewController_iPhone alloc] initWithNibName:@"StyleDetailViewController_iPhone" bundle:nil];
}
else if (g_IS_IPHONE_5_SCREEN){
styleDetailObj =[[StyleDetailViewController_iPhone alloc] initWithNibName:@"StyleDetailViewController_iPhone5" bundle:nil];
}
[self.navigationController pushViewController:styleDetailObj animated:NO];