Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/114.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 如何将多个自定义视图添加到UIScrollview中_Iphone_Ios_Ios6 - Fatal编程技术网

Iphone 如何将多个自定义视图添加到UIScrollview中

Iphone 如何将多个自定义视图添加到UIScrollview中,iphone,ios,ios6,Iphone,Ios,Ios6,我正在开发一个应用程序,我需要以下功能 从服务器下载多个图像文件 将其显示为网格格式 为满足上述要求 我使用.xib文件创建了自定义视图。并将其添加到scrollview中 但是对于如何异步下载图像并将其显示在适当的位置,我没有任何想法 我在网格样式中添加自定义视图的代码如下 -(void)LazyLoading_display_Objects_in_grid_style { for(int i=0; i<[imageListingArray count] ; i++)

我正在开发一个应用程序,我需要以下功能

  • 从服务器下载多个图像文件
  • 将其显示为网格格式
  • 为满足上述要求

    我使用.xib文件创建了自定义视图。并将其添加到scrollview中

    但是对于如何异步下载图像并将其显示在适当的位置,我没有任何想法

    我在网格样式中添加自定义视图的代码如下

    -(void)LazyLoading_display_Objects_in_grid_style
    {
    
        for(int i=0; i<[imageListingArray count] ; i++)
        {
            NSArray *arr = [[NSBundle mainBundle] loadNibNamed:@"MyView" owner:nil options:nil];
            MyView *myView = (MyView *)[arr objectAtIndex:0];
            myView.frame = CGRectMake(x,y,width,height);
    myView.imgPhoto setContentMode:UIViewContentModeScaleAspectFit];
            myView.imageURL = [NSString stringWithFormat:@"%@",[[imageListingArray objectAtIndex:i] valueForKey:@"name"]];
     [myView setBackgroundColor:[UIColor clearColor]];
    
            if(myView.imgPhoto.image == nil)
                [myView.actLoading startAnimating];
    
            [myView.imgPhoto setTag:1000+i];
    
            [myView setUserInteractionEnabled:TRUE];
            myView.tag = 100+i;
    
            [self.imageListingScrollView addSubview:myView];
    
            if(current_no_of_object_in_row !=noOfObjectInColumn)
            {
                x =x + width + 8 ;
                current_no_of_object_in_row ++;
            }
            else
            {
                current_no_of_object_in_row =1;
                x = 5;
                y = y+ height + 8 ;
            }
            scrollView_Height = y;
        }
    int temp = [imageListingArray count]%noOfObjectInColumn;
    
        if(temp>0)
        {
            NSLog(@"No modulus");
            y = y + height+ 10;
        }
        scrollView_Height = y;
        NSLog(@"Scroll Height : %d",scrollView_Height);
        [self.imageListingScrollView setContentSize:CGSizeMake(308, scrollView_Height+ 5)];
    }
    
    -(void)懒散加载以网格样式显示对象
    {
    对于(int i=0;i0)
    {
    NSLog(“无模数”);
    y=y+高度+10;
    }
    滚动视图_高度=y;
    NSLog(@“滚动高度:%d”,滚动视图\u高度);
    [self.imageListingScrollView设置内容大小:CGSizeMake(308,scrollView_Height+5)];
    }
    
    您可以选择UITableView,而不是创建多个视图。它可以作为UIScrollView和网格显示。此链接可能会帮助您:


    拿一个UITableView实例,像这样旋转它:

    CGAffineTransform transform = CGAffineTransformMakeRotation(M_PI/2.0f);    
    table.transform = transform;  
    
    您可能还需要在UITableView中旋转单元格,类似于

    - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
      CGAffineTransform transform = CGAffineTransformMakeRotation(M_PI/2.0f);
      cell.transform = transform;
    }
    

    如果以UIScrollView为例,那么您必须处理内存可能会签出

    您可以尝试使用AsyncImageView类。它是UIImage的扩展,允许从直接URL异步下载映像。我在很多项目中使用类似的扩展。您只需调用方法

    - (void)loadImageWithURL:(NSURL *)URL;
    
    当检索数据时,图像将显示在此视图中。

    如果为所有iOS的UITableView创建iOS 6+项目,则可以使用UICollectionView类创建网格。
    如果您要使用UITableView,您可以使用左右两侧的两个AsyncImageView对象创建自定义单元格。

    Hi Ishank,谢谢您的回答。我使用JMCaching库下载图像。第一次,它会下载图像,之后每次都会从缓存中获取。我有一个非常好的API,你可以用它来缓存图像。请给我你的电子邮件地址,我会转发给你。谢谢你的回答。我去看看。