0

我正在使用需要允许以适合 iPhone 5 屏幕的视图,但是我似乎无法正确布局,我已经尝试过了;

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;
    }

顶部是错误的,iPhone 5 的布局不正确,我想知道是否有人可以帮助我提供一个更简洁的代码示例来使用?

谢谢,克里斯

4

3 回答 3

1

您可以使用以下命令检查您的设备分辨率是 iPhone 5(4 英寸)还是更低分辨率(3.5 英寸)

#define IS_IPHONE ( [[[UIDevice currentDevice] model] isEqualToString:@"iPhone"] | [[[UIDevice currentDevice] model] isEqualToString:@"iPhone Simulator"])
#define IS_HEIGHT_GTE_568 [[UIScreen mainScreen ] bounds].size.height >= 568.0f
#define IS_IPHONE_5 ( IS_IPHONE && IS_HEIGHT_GTE_568 )

然后你可以通过用下面的代码替换你的代码来设置框架:

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,而在 iPhone 4 中为 320。虽然两种设备的宽度相同。所以我在这两种情况下都改变了宽度 320。

它会为你工作。

于 2013-04-27T03:33:01.457 回答
0

通过执行以下操作检查屏幕高度:

        screenRect = [UIScreen mainScreen].bounds;
        screenHeight = screenRect.size.height;
        if( screenHeight == 568){
            NSLog(@"iPhone 5");
         }
        else NSLog (@"iPhone 4s or below");

根据屏幕尺寸设置框架时,请确保您在导航栏中计算是否有一个(默认约为 40 像素)和状态栏,我认为是 10 像素。

此外宽度仍为 320 像素,操作系统将自动调整视网膜显示。

于 2013-04-26T19:01:53.233 回答
0

只需为 iphone4 和 iphne5 取两个 .xib。它很容易,无需设置框架,只需推送正确的 View/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 

当你按下然后检查屏幕..

    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];
于 2013-04-27T05:07:16.620 回答