2

我正在开发一个应用程序,该应用程序显示 20 个数组图像到图像视图水平滚动。

像这样为该图像视图提供滚动视图

scrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, 320, 480)];
for (m = 0; m <=19; m++)
    {
        rnd = arc4random_uniform(arr.count);

        NSString *imageName=[FrontsCards objectAtIndex:rnd];

    fullImageName=[NSString stringWithFormat:@"%@",imageName];

        int padding=0;

        CGRect imageViewFrame=CGRectMake(scrollView.frame.size.width*m+padding, scrollView.frame.origin.y, scrollView.frame.size.width-2*padding, scrollView.frame.size.height);

        ImgView=[[UIImageView alloc]initWithFrame:imageViewFrame];


        [ImgView setImage:[UIImage imageNamed:fullImageName]];

        [scrollView addSubview:ImgView];
     }

此图像视图无法正确显示图像,适用于 iphone 5 模拟器。在黑边下方添加。我该如何解决这个问题。如何删除那个黑边。如何将该图像适合 Iphone 5 模拟器。

如何将我的 ImageView 管理到 Iphone 4 或 Iphone 5。

4

6 回答 6

2

Iphone 5 screen size is 568 and you have had codded height to 480. So it is not working for iphone5. DO following

scrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, 320, [[UIScreen mainScreen] bounds].size.height)];

Depending on devise scroll view height will change.

于 2013-05-28T06:04:19.740 回答
2

Iphone 5 尺寸为 568,Iphone 4 尺寸为 480。

scrollView=[[UIScrollView alloc]init];

if ([[UIScreen mainScreen] bounds].size.height == 568) 
{  

    // For Iphone5
scrollView.frame = CGRectMake(0, 0, 320, 568)
}
else if ([[UIScreen mainScreen] bounds].size.height == 480) 
{
   //For Iphone 4 or others
scrollView.frame = CGCGRectMake(0, 0, 320, 480)
}

这对你真的很有帮助。

于 2013-05-28T06:46:19.193 回答
0

You need to create design for iPhone 4 and iPhone 5.

Create a class which make decision which iPhone is connected and make function on it which accept CGRect and return required size of CGRect

you can get device size by

if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
    {
        CGSize result = [[UIScreen mainScreen] bounds].size;
        if (result.height < 500)
        {
            currentDeviceHeight=460;
            //You can use use iPhone 4 image

        }
        else
        {
            currentDeviceHeight=548;
            // here you can use iPhone 5 image
        }
    }
    else
    {
         // iPad
    }
于 2013-05-28T06:02:37.460 回答
0

使用宏来检查它是否是 iPhone 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 )

scrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, 320, IS_IPHONE_5?568:480)];
于 2013-05-28T06:19:27.447 回答
0
scrollView=[[UIScrollView alloc]initWithFrame:[[UIScreen mainScreen]bounds]];

用它来制作UIScrollView动态

于 2013-05-28T06:08:01.693 回答
0

尝试这个

scrollView=[[UIScrollView alloc]init];

if ([[UIScreen mainScreen] bounds].size.height == 568) scrollView.frame = CGRectMake(0, 0, 320, 568)
else if ([[UIScreen mainScreen] bounds].size.height == 480) scrollView.frame = CGRectMake(0, 0, 320, 480)

因此,它也将帮助您在 iPhone-5 屏幕中填充滚动视图。

希望它对你有用。

谢谢。

于 2013-05-28T06:00:22.917 回答