diff --git a/RGPaperLayout/Base.lproj/Main.storyboard b/RGPaperLayout/Base.lproj/Main.storyboard index f832816..d347830 100644 --- a/RGPaperLayout/Base.lproj/Main.storyboard +++ b/RGPaperLayout/Base.lproj/Main.storyboard @@ -1,5 +1,5 @@ - + @@ -89,6 +89,7 @@ + diff --git a/RGPaperLayout/ViewController.m b/RGPaperLayout/ViewController.m index b08f604..2e77b14 100644 --- a/RGPaperLayout/ViewController.m +++ b/RGPaperLayout/ViewController.m @@ -10,9 +10,13 @@ #import "ViewController.h" #import "RGCollectionViewCell.h" -@interface ViewController () +@interface ViewController () + @property (weak, nonatomic) IBOutlet UICollectionView *collectionView; @property NSMutableArray *listOfData; +@property (nonatomic, strong) UIImageView *imageView; +@property (nonatomic, strong) UIImageView *mainImageView; + @end @@ -23,31 +27,45 @@ - (void)viewDidLoad { // Do any additional setup after loading the view, typically from a nib. self.listOfData = [@[@"climb",@"ice",@"lake",@"shark",@"whale",@"climb",@"ice",@"lake",@"shark",@"whale",@"climb",@"ice",@"lake",@"shark",@"whale"]mutableCopy]; + [self setupEffectImage:[UIImage imageNamed:@"climb"]]; +} + +- (void)didReceiveMemoryWarning { + [super didReceiveMemoryWarning]; + // Dispose of any resources that can be recreated. +} + +#pragma mark - Blur Effect Helper Method + +- (void)setupEffectImage:(UIImage *)effectImage { //---> setting up the look of the collection View + the main View UIVisualEffect *effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark]; + UIVisualEffectView *effectView = [[UIVisualEffectView alloc]initWithEffect:effect]; effectView.frame = self.collectionView.bounds; - UIImageView *imageView = [[UIImageView alloc]initWithFrame:self.collectionView.bounds]; - imageView.image = [UIImage imageNamed:@"ice"]; + + self.imageView = [[UIImageView alloc]initWithFrame:self.collectionView.bounds]; + self.imageView.image = effectImage; UIView *viewFrame = [[UIView alloc]initWithFrame:self.collectionView.bounds]; - [viewFrame addSubview:imageView]; + [viewFrame addSubview:self.imageView]; [viewFrame addSubview:effectView]; self.collectionView.backgroundView = viewFrame; - UIVisualEffectView *mainEffectView = [[UIVisualEffectView alloc]initWithEffect:effect]; mainEffectView.frame = self.view.bounds; - UIImageView *mainImageView = [[UIImageView alloc]initWithFrame:self.view.bounds]; - mainImageView.image = [UIImage imageNamed:@"ice"]; - UIView *mainViewFrame = [[UIView alloc]initWithFrame:self.view.bounds]; - [mainViewFrame addSubview:mainImageView]; + + self.mainImageView = [[UIImageView alloc]initWithFrame:self.view.bounds]; + self.mainImageView.image = effectImage; + + UIView *mainViewFrame = [[UIView alloc] initWithFrame:self.view.bounds]; + [mainViewFrame addSubview:self.mainImageView]; [mainViewFrame addSubview:mainEffectView]; [self.view insertSubview:mainViewFrame belowSubview:self.collectionView]; - } + #pragma mark - UICollectionViewDataSource - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView @@ -70,17 +88,22 @@ - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView return cell; } +- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { + [self selectedItemAtIndexPath:indexPath]; +} + +- (void)selectedItemAtIndexPath:(NSIndexPath *)indexPath { + NSString *nameOfImage = self.listOfData[indexPath.section]; + self.imageView.image = [UIImage imageNamed:nameOfImage]; + self.mainImageView.image = [UIImage imageNamed:nameOfImage]; +} + - (void)configureCell:(RGCollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath { NSString *nameOfImage = self.listOfData[indexPath.section]; cell.imageView.image = [UIImage imageNamed:nameOfImage]; cell.label.text = nameOfImage; - -} -- (void)didReceiveMemoryWarning { - [super didReceiveMemoryWarning]; - // Dispose of any resources that can be recreated. } @end