2013-03-09 31 views
1

嗨朋友,我必須開發一個照片管理應用程序。在這裏我的圖像應該安排在我的iphone.i在谷歌我分析框架的工作。下面的列表是Iphone中的網格視圖實現?

1.UICollectionView

2. AQGridView

3. PSTCollectionView

,也是我在網格視圖功能如下

  1. 列出的應用程序應該是兼容與以上4.3 iOS
  2. 網格查看單元格允許UITapGestureRecognizer刪除圖像單元或編輯樣式選項,如表格視圖。

  3. 創建自定義的GridView細胞

請任何一個可以sugest我哪一個是好開發

回答

1

如果您創建自定義按鈕,將圖像路徑存儲在數組中,編寫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)]; 

說明

圖像的路徑被存儲在的ImagePath。然後我們將imagePath存儲在一個字符串(路徑)中。現在,對imageArray,我們添加路徑的內容。因此imageArray現在包含所有圖像的路徑。然後創建一個for循環來顯示每行4個圖像。創建一個自定義按鈕和按鈕,逐個插入每個圖像(使用imageArray)。創建一個滾動視圖來放置所有的按鈕圖像。

您現在已完成爲圖像創建4 * 4網格視圖。編碼快樂......我目前使用AQGridView所以我肯定建議

0

好像PSTCollectionView是你所需要的。

它就像UICollectionView,但適用於iOS 4.3。

您可以通過重寫數據源方法來創建自定義單元格:

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

另外,在這種方法中,你可以手勢識別器添加到您的細胞。

+0

是在IOS 5和iOS 6此框架支撐 – Vijay 2013-03-09 11:57:28

+0

是,min是的iOS 4.3(iOS5的&iOS6的爲好) – 2013-03-09 12:29:37

+0

[PSTCollectionView](https://github.com/steipete/PSTCollectionView) – Bala 2013-03-29 11:54:29

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