gpt4 book ai didi

iphone - iPhone 5 View 布局协助

转载 作者:行者123 更新时间:2023-11-29 03:58:06 24 4
gpt4 key购买 nike

我正在使用需要适合 iPhone 5 屏幕的 View ,但我似乎无法获得正确的布局,我已经尝试过了;

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 的布局不正确,我想知道是否有人可以帮助我提供一个更简洁的代码示例来使用?

谢谢,克里斯

最佳答案

您可以使用

检查您的设备分辨率是否为 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。

这对你有用。

关于iphone - iPhone 5 View 布局协助,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16243385/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com