CollectionViewManager.h
#import <Foundation/Foundation.h>
#import “CollectionViewFlowLayout.h”
#import “CollectionViewCell.h”
#import “Constant.h”
typedef void (^DidTapOnCollectionViewCell)(NSInteger IndexpathRow, NSString *imageURL);
//typedef void (^DidTapOnCloseButton) (NSString *str);
@interface CollectionViewManager : NSObject<UICollectionViewDataSource,UICollectionViewDelegate,CellDelegate>
{
CGRect aFrame;
NSIndexPath *aIndexPath;
}
@property (nonatomic, retain) UICollectionView *collectionView;
@property (nonatomic, retain) NSMutableArray *arrMain;
@property (nonatomic, copy) DidTapOnCollectionViewCell didTapOnCollectionViewCell;
//@property (nonatomic, copy) DidTapOnCloseButton didTapOnCloseButton;
-(id)initwithCollectionView:(UICollectionView *)aCollectionView dataSourve:(NSMutableArray *)aDataSource withTapOnCollectionViewCellBlock:(DidTapOnCollectionViewCell)aBlock;
– (void)reloadCollectionViewData;
@end
CollectionViewManager.m
#import “CollectionViewManager.h”
@implementation CollectionViewManager
-(id)initwithCollectionView:(UICollectionView *)aCollectionView dataSourve:(NSMutableArray *)aDataSource withTapOnCollectionViewCellBlock:(DidTapOnCollectionViewCell)aBlock
{
if (self == [super init])
{
self.didTapOnCollectionViewCell = aBlock;
self.collectionView = aCollectionView;
self.collectionView.delegate = self;
self.collectionView.dataSource = self;
self.arrMain = aDataSource;
}
return self;
}
#pragma mark – CollectionView Reload
– (void)reloadCollectionViewData
{
[self.collectionView reloadData];
}
#pragma mark – CollectionView Delegate
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return [self.arrMain count];
}
– (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *staticIdentifier = @”Cell”;
CollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:staticIdentifier forIndexPath:indexPath];
[cell setupImage:[self.arrMain objectAtIndex:indexPath.row]];
cell.delegate = self;
cell.btnClose.tag = indexPath.row;
return cell;
}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@”%ld”,(long)indexPath.row);
self.didTapOnCollectionViewCell(indexPath.row,[self.arrMain objectAtIndex:indexPath.row]);
// // animate the cell user tapped on
// UICollectionViewCell *cell = [collectionView cellForItemAtIndexPath:indexPath];
//
// aFrame = cell.frame;
// aIndexPath = indexPath;
//
// NSLog(@”%f”,WD);
// NSLog(@”%f”,HT);
//
// [UIView animateWithDuration:1.0
// delay:0
// options:(UIViewAnimationOptionAllowUserInteraction)
// animations:^{
// NSLog(@”animation start”);
// cell.frame = CGRectMake(WD/3, HT/3, cell.frame.size.width, cell.frame.size.height);
// [self.collectionView bringSubviewToFront:cell];
// }
// completion:^(BOOL finished){
// NSLog(@”animation end”);
// // [cell setBackgroundColor:[UIColor whiteColor]];
//
// }
// ];
}
– (void)closeButtonPressedAtCellIndex:(NSInteger)cellIndex
{
NSLog(@”closeButtonPressedAtCellIndex”);
NSLog(@”%ld”,(long)cellIndex);
[self.collectionView reloadData];
UICollectionViewCell *cell = [self.collectionView cellForItemAtIndexPath:aIndexPath];
// aFrame = cell.frame;
// aIndexPath = indexPath.row;
[UIView animateWithDuration:1.0
delay:0
options:(UIViewAnimationOptionAllowUserInteraction)
animations:^{
NSLog(@”animation start”);
cell.frame = aFrame;
}
completion:^(BOOL finished){
NSLog(@”animation end”);
// [cell setBackgroundColor:[UIColor whiteColor]];
}
];
}
@end