Iphone中的网格视图实现?

Iphone中的网格视图实现?,iphone,ios,gridview,photo-gallery,Iphone,Ios,Gridview,Photo Gallery,嗨,朋友们,我必须开发一个照片管理应用程序。在这里,我的图像应该在iphone的gris视图中排列。我在谷歌中分析,得到了一些框架。下面的列表是 1.UICollectionView 二, 三, 下面列出了我在grid view中的功能 该应用程序应与上述4.3 iOS兼容 网格视图单元格允许UITapGestureRecognizer删除图像单元格或编辑样式选项,如在表格视图中 创建自定义GridView单元 请任何人告诉我哪一个适合开发似乎PSTCollectionView就是您所需要的 它

嗨,朋友们,我必须开发一个照片管理应用程序。在这里,我的图像应该在iphone的gris视图中排列。我在谷歌中分析,得到了一些框架。下面的列表是

1.UICollectionView

二,

三,

下面列出了我在grid view中的功能

  • 该应用程序应与上述4.3 iOS兼容
  • 网格视图单元格允许
    UITapGestureRecognizer
    删除图像单元格或编辑样式选项,如在表格视图中

  • 创建自定义GridView单元


  • 请任何人告诉我哪一个适合开发

    似乎PSTCollectionView就是您所需要的

    它类似于UICollectionView,但适用于iOS 4.3

    可以通过重写dataSource方法创建自定义单元格:

    - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
    

    同样,在这种方法中,您可以将手势识别器添加到单元格中。

    似乎PSTCollectionView就是您所需要的

    它类似于UICollectionView,但适用于iOS 4.3

    可以通过重写dataSource方法创建自定义单元格:

    - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
    

    同样,在这种方法中,您可以将手势识别器添加到单元格中。

    最好创建自定义按钮,将图像路径存储在数组中,编写for循环以显示每行中的图像数量。在每个自定义按钮中插入这些图像。它现在看起来像一个缩略图图像视图

    像这样的,

    imageArray =[[NSMutableArray alloc]init];
                   for (NSString* path in imagePath)
                   {
                       [imageArray addObject:[UIImage imageWithContentsOfFile:path]];
                       NSLog(@"%@",path);
                   }
                   NSLog(@"%@",imageArray);
    
               NSLog(@"Yes");
    
               myScrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0.0, 0.0, 320.0, 840.0)];
               myScrollView.delegate = self;
               myScrollView.contentSize = CGSizeMake(320.0, 840.0);
               myScrollView.backgroundColor = [UIColor whiteColor];
               [self.view addSubview:myScrollView];
    
               float horizontal = 8.0;
               float vertical = 8.0;
    
               for(int i=0; i<[imageArray count]; i++)
               {
                   if((i%4) == 0 && i!=0)
                   {
                       horizontal = 8.0;
                       vertical = vertical + 70.0 + 8.0;
                   }
    
                   buttonImage = [UIButton buttonWithType:UIButtonTypeCustom];
                   [buttonImage setFrame:CGRectMake(horizontal, vertical, 70.0, 70.0)];
                   [buttonImage setTag:i];
    
                   [buttonImage setImage:[imageArray objectAtIndex:i] forState:UIControlStateNormal];
                   [buttonImage addTarget:self action:@selector(buttonImagePressedSmiley forControlEvents:UIControlEventTouchUpInside];
                   [buttonImage setImage:[UIImage imageNamed:@"check.jpg"] forState:UIControlStateSelected];
    
    
                   [myScrollView addSubview:buttonImage];
    
                   horizontal = horizontal + 70.0 + 8.0;
               }
    
               [myScrollView setContentSize:CGSizeMake(320.0, vertical + 78.0)];
    
    imageArray=[[NSMutableArray alloc]init];
    for(图像路径中的NSString*路径)
    {
    [imageArray添加对象:[UIImage imageWithContentsOfFile:path]];
    NSLog(@“%@”,路径);
    }
    NSLog(@“%@”,图像阵列);
    NSLog(@“是”);
    myScrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(0.0,0.0320.0840.0)];
    myScrollView.delegate=self;
    myScrollView.contentSize=CGSizeMake(320.0840.0);
    myScrollView.backgroundColor=[UIColor whiteColor];
    [self.view addSubview:myScrollView];
    水平浮动=8.0;
    垂直浮动=8.0;
    
    for(int i=0;i最好创建自定义按钮,将图像路径存储在数组中,编写for循环以显示每行中的图像数。将这些图像插入每个自定义按钮中。它现在看起来像一个缩略图图像视图

    像这样的,

    imageArray =[[NSMutableArray alloc]init];
                   for (NSString* path in imagePath)
                   {
                       [imageArray addObject:[UIImage imageWithContentsOfFile:path]];
                       NSLog(@"%@",path);
                   }
                   NSLog(@"%@",imageArray);
    
               NSLog(@"Yes");
    
               myScrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0.0, 0.0, 320.0, 840.0)];
               myScrollView.delegate = self;
               myScrollView.contentSize = CGSizeMake(320.0, 840.0);
               myScrollView.backgroundColor = [UIColor whiteColor];
               [self.view addSubview:myScrollView];
    
               float horizontal = 8.0;
               float vertical = 8.0;
    
               for(int i=0; i<[imageArray count]; i++)
               {
                   if((i%4) == 0 && i!=0)
                   {
                       horizontal = 8.0;
                       vertical = vertical + 70.0 + 8.0;
                   }
    
                   buttonImage = [UIButton buttonWithType:UIButtonTypeCustom];
                   [buttonImage setFrame:CGRectMake(horizontal, vertical, 70.0, 70.0)];
                   [buttonImage setTag:i];
    
                   [buttonImage setImage:[imageArray objectAtIndex:i] forState:UIControlStateNormal];
                   [buttonImage addTarget:self action:@selector(buttonImagePressedSmiley forControlEvents:UIControlEventTouchUpInside];
                   [buttonImage setImage:[UIImage imageNamed:@"check.jpg"] forState:UIControlStateSelected];
    
    
                   [myScrollView addSubview:buttonImage];
    
                   horizontal = horizontal + 70.0 + 8.0;
               }
    
               [myScrollView setContentSize:CGSizeMake(320.0, vertical + 78.0)];
    
    imageArray=[[NSMutableArray alloc]init];
    for(图像路径中的NSString*路径)
    {
    [imageArray添加对象:[UIImage imageWithContentsOfFile:path]];
    NSLog(@“%@”,路径);
    }
    NSLog(@“%@”,图像阵列);
    NSLog(@“是”);
    myScrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(0.0,0.0320.0840.0)];
    myScrollView.delegate=self;
    myScrollView.contentSize=CGSizeMake(320.0840.0);
    myScrollView.backgroundColor=[UIColor whiteColor];
    [self.view addSubview:myScrollView];
    水平浮动=8.0;
    垂直浮动=8.0;
    
    对于(int i=0;i我目前使用的是
    AQGridView
    ,因此我当然建议使用它,因为它的错误最少,其功能与
    UITableView
    非常类似


    另外,如果您试图在没有XIB的情况下执行此操作,那么处理它会有点困难,但是您可以使用XIB文件创建视图控制器来创建您选择的界面我建议您使用它,因为它的错误最少,而且它的功能非常类似于
    UITableView

    ViewController.h
    
    {
       NSMutableArray *galleryarray;
    }
    @property (retain, nonatomic) IBOutlet UIScrollView *scrolll_photo;
    
    ViewController.m
    
     [self gallery];
    
    Secondview.h
    
      NSMutableArray *imagesArraySlide;
         int imageCount;
    
    @property (retain, nonatomic) IBOutlet UIScrollView *photoscroll;
    @property (nonatomic, retain) NSMutableArray *imagesArraySlide;
    @property (readwrite) int imageCount;
    @property (readwrite) int imageID;
    
    
    Secondview.m
    
     [self loadphoto];
    
    -(void)loadphoto
    {
        NSArray *viewsToRemove = [_photoscroll subviews];
        for (UIView *view in viewsToRemove)
        {
            [view removeFromSuperview];
        }
        imageCount = [imagesArraySlide count];
        _photoscroll.delegate = self;
        _photoscroll.contentSize=CGSizeMake(320*imageCount, 380);
        _photoscroll.scrollEnabled = TRUE;
        _photoscroll.pagingEnabled = TRUE;
    
        int scroll_x=0;
        for(int i=1; i<=imageCount; i++)
        {
            UIImageView *imageView1 = [[UIImageView alloc] initWithFrame:CGRectMake(scroll_x, 20, 320, 380)];
            imageView1.contentMode = UIViewContentModeScaleAspectFit;
            imageView1.clipsToBounds = NO;
            imageView1.autoresizingMask = UIViewContentModeScaleAspectFit;
            imageView1.image=[UIImage imageNamed:[imagesArraySlide objectAtIndex:i-1]];
            [_photoscroll addSubview:imageView1];
            [imageView1 release];
            scroll_x = scroll_x + 320;
        }
        [_photoscroll setContentOffset:CGPointMake(imageID*320, 0) animated:NO];
        self.title = [NSString stringWithFormat:@"%d of %d",imageID+1,imageCount];
    }
    -(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
    {
        imageID = scrollView.contentOffset.x / scrollView.frame.size.width;
        self.title = [NSString stringWithFormat:@"%d of %d",imageID+1,imageCount];
    }
    - (void)scrollViewDidScroll:(UIScrollView *)scrollView
    {
        self.title = [NSString stringWithFormat:@"%d of %d",imageID+1,imageCount];
    }
    
    另外,如果您试图在不使用XIB的情况下执行此操作,则处理它会有点困难,但您可以使用XIB文件创建视图控制器,以创建您选择的界面。by
    Evadne Wu
    。示例项目是
    ViewController.h
    
    ViewController.h
    
    {
       NSMutableArray *galleryarray;
    }
    @property (retain, nonatomic) IBOutlet UIScrollView *scrolll_photo;
    
    ViewController.m
    
     [self gallery];
    
    Secondview.h
    
      NSMutableArray *imagesArraySlide;
         int imageCount;
    
    @property (retain, nonatomic) IBOutlet UIScrollView *photoscroll;
    @property (nonatomic, retain) NSMutableArray *imagesArraySlide;
    @property (readwrite) int imageCount;
    @property (readwrite) int imageID;
    
    
    Secondview.m
    
     [self loadphoto];
    
    -(void)loadphoto
    {
        NSArray *viewsToRemove = [_photoscroll subviews];
        for (UIView *view in viewsToRemove)
        {
            [view removeFromSuperview];
        }
        imageCount = [imagesArraySlide count];
        _photoscroll.delegate = self;
        _photoscroll.contentSize=CGSizeMake(320*imageCount, 380);
        _photoscroll.scrollEnabled = TRUE;
        _photoscroll.pagingEnabled = TRUE;
    
        int scroll_x=0;
        for(int i=1; i<=imageCount; i++)
        {
            UIImageView *imageView1 = [[UIImageView alloc] initWithFrame:CGRectMake(scroll_x, 20, 320, 380)];
            imageView1.contentMode = UIViewContentModeScaleAspectFit;
            imageView1.clipsToBounds = NO;
            imageView1.autoresizingMask = UIViewContentModeScaleAspectFit;
            imageView1.image=[UIImage imageNamed:[imagesArraySlide objectAtIndex:i-1]];
            [_photoscroll addSubview:imageView1];
            [imageView1 release];
            scroll_x = scroll_x + 320;
        }
        [_photoscroll setContentOffset:CGPointMake(imageID*320, 0) animated:NO];
        self.title = [NSString stringWithFormat:@"%d of %d",imageID+1,imageCount];
    }
    -(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
    {
        imageID = scrollView.contentOffset.x / scrollView.frame.size.width;
        self.title = [NSString stringWithFormat:@"%d of %d",imageID+1,imageCount];
    }
    - (void)scrollViewDidScroll:(UIScrollView *)scrollView
    {
        self.title = [NSString stringWithFormat:@"%d of %d",imageID+1,imageCount];
    }
    
    { NSMutableArray*galleryarray; } @属性(保留,非原子)IBUIScrollView*Scroll_照片; ViewController.m [自我画廊]; Secondview.h NSMutableArray*图像阵列幻灯片; int图像计数; @属性(保留,非原子)IBUIScrollView*photoscroll; @属性(非原子,保留)NSMutableArray*ImagesArray幻灯片; @属性(读写)int-imageCount; @属性(读写)int-imageID; Secondview.m [自拍照片]; -(无效)装载照片 { NSArray*viewsToRemove=[\u photoscroll子视图]; 用于(UIView*viewsToRemove中的视图) { [视图从SuperView移除]; } imageCount=[ImageSarray幻灯片计数]; _photoscroll.delegate=self; _photoscroll.contentSize=CGSizeMake(320*imageCount,380); _photoscroll.scrollEnabled=TRUE; _photoscroll.PaginEnabled=真; int scroll_x=0; 对于(inti=1;i
    ViewController.h
    {
    NSMutableArray*galleryarray;
    }
    @属性(保留,非原子)IBUIScrollView*Scroll_照片;
    ViewController.m
    [自我画廊];
    Secondview.h
    NSMutableArray*图像阵列幻灯片;
    int图像计数;
    @属性(保留,非原子)IBUIScrollView*photoscroll;
    @属性(非原子,保留)NSMutableArray*ImagesArray幻灯片;
    @属性(读写)int-imageCount;
    @属性(读写)int-imageID;
    Secondview.m
    [自拍照片];
    -(无效)装载照片
    {
    NSArray*viewsToRemove=[\u photoscroll子视图];
    用于(UIView*viewsToRemove中的视图)
    {
    [视图从SuperView移除];
    }
    imageCount=[ImageSarray幻灯片计数];
    _photoscroll.delegate=self;
    _photoscroll.contentSize=CGSizeMake(320*imageCount,380);
    _photoscroll.scrollEnabled=TRUE;
    _photoscroll.PaginEnabled=真;
    int scroll_x=0;
    对于(inti=1;iYes,min是ios4.3(以及iOS5和iOS6)是的,min是ios4.3(以及iOS5和iOS6)