Skip to content
This repository has been archived by the owner on Dec 6, 2018. It is now read-only.

Commit

Permalink
Basics of view controller hierarchy setup.
Browse files Browse the repository at this point in the history
  • Loading branch information
ashfurrow committed Oct 16, 2013
1 parent 1f404ff commit 1003257
Show file tree
Hide file tree
Showing 8 changed files with 217 additions and 4 deletions.
24 changes: 22 additions & 2 deletions FRP.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

/* Begin PBXBuildFile section */
2826EB375D254DDD8DE6EAA8 /* libPods-FRP.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 772BE9E4C5824F1C8E5CDC45 /* libPods-FRP.a */; };
5E595111180E065F002F44FA /* FRPFullSizePhotoViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 5E595110180E065F002F44FA /* FRPFullSizePhotoViewController.m */; };
5E595117180E0C33002F44FA /* FRPPhotoViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 5E595116180E0C33002F44FA /* FRPPhotoViewController.m */; };
5EBC599E180B247500B683A7 /* FRPCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 5EBC599D180B247500B683A7 /* FRPCell.m */; };
5EBC59A6180B2AA200B683A7 /* FRPPhotoImporter.m in Sources */ = {isa = PBXBuildFile; fileRef = 5EBC59A5180B2AA200B683A7 /* FRPPhotoImporter.m */; };
5EBC59A9180B2C4F00B683A7 /* FRPGalleryFlowLayout.m in Sources */ = {isa = PBXBuildFile; fileRef = 5EBC59A8180B2C4F00B683A7 /* FRPGalleryFlowLayout.m */; };
Expand Down Expand Up @@ -38,6 +40,10 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
5E59510F180E065F002F44FA /* FRPFullSizePhotoViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FRPFullSizePhotoViewController.h; sourceTree = "<group>"; };
5E595110180E065F002F44FA /* FRPFullSizePhotoViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FRPFullSizePhotoViewController.m; sourceTree = "<group>"; };
5E595115180E0C33002F44FA /* FRPPhotoViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FRPPhotoViewController.h; sourceTree = "<group>"; };
5E595116180E0C33002F44FA /* FRPPhotoViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FRPPhotoViewController.m; sourceTree = "<group>"; };
5EBC599C180B247500B683A7 /* FRPCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FRPCell.h; sourceTree = "<group>"; };
5EBC599D180B247500B683A7 /* FRPCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FRPCell.m; sourceTree = "<group>"; };
5EBC59A0180B268600B683A7 /* FRPPhotoModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FRPPhotoModel.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -95,6 +101,19 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
5E59510E180E0634002F44FA /* View Controllers */ = {
isa = PBXGroup;
children = (
5EBE2B29180B0AF1007B6BF3 /* FRPGalleryViewController.h */,
5EBE2B2A180B0AF1007B6BF3 /* FRPGalleryViewController.m */,
5E59510F180E065F002F44FA /* FRPFullSizePhotoViewController.h */,
5E595110180E065F002F44FA /* FRPFullSizePhotoViewController.m */,
5E595115180E0C33002F44FA /* FRPPhotoViewController.h */,
5E595116180E0C33002F44FA /* FRPPhotoViewController.m */,
);
name = "View Controllers";
sourceTree = "<group>";
};
5EBC599F180B267400B683A7 /* UICollectionView Extensions */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -153,10 +172,9 @@
children = (
5EBE2B05180B07D0007B6BF3 /* FRPAppDelegate.h */,
5EBE2B06180B07D0007B6BF3 /* FRPAppDelegate.m */,
5EBE2B29180B0AF1007B6BF3 /* FRPGalleryViewController.h */,
5EBE2B2A180B0AF1007B6BF3 /* FRPGalleryViewController.m */,
5EBC59A4180B2AA200B683A7 /* FRPPhotoImporter.h */,
5EBC59A5180B2AA200B683A7 /* FRPPhotoImporter.m */,
5E59510E180E0634002F44FA /* View Controllers */,
5EBC59A3180B268A00B683A7 /* Models */,
5EBC599F180B267400B683A7 /* UICollectionView Extensions */,
5EBE2B0B180B07D0007B6BF3 /* Images.xcassets */,
Expand Down Expand Up @@ -326,8 +344,10 @@
buildActionMask = 2147483647;
files = (
5EBC599E180B247500B683A7 /* FRPCell.m in Sources */,
5E595111180E065F002F44FA /* FRPFullSizePhotoViewController.m in Sources */,
5EBC59A9180B2C4F00B683A7 /* FRPGalleryFlowLayout.m in Sources */,
5EBE2B03180B07D0007B6BF3 /* main.m in Sources */,
5E595117180E0C33002F44FA /* FRPPhotoViewController.m in Sources */,
5EBC59A6180B2AA200B683A7 /* FRPPhotoImporter.m in Sources */,
5EBE2B2B180B0AF1007B6BF3 /* FRPGalleryViewController.m in Sources */,
5EBE2B07180B07D0007B6BF3 /* FRPAppDelegate.m in Sources */,
Expand Down
2 changes: 0 additions & 2 deletions FRP/FRP-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
</dict>
</plist>
18 changes: 18 additions & 0 deletions FRP/FRPFullSizePhotoViewController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// FRPFullSizePhotoViewController.h
// FRP
//
// Created by Ash Furrow on 10/15/2013.
// Copyright (c) 2013 Ash Furrow. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface FRPFullSizePhotoViewController : UIViewController

-(instancetype)initWithPhotoModels:(NSArray *)photoModelArray currentPhotoIndex:(NSInteger)photoIndex;

@property (nonatomic, readonly) NSArray *photoModelArray;
@property (nonatomic, readonly) NSInteger photoIndex;

@end
81 changes: 81 additions & 0 deletions FRP/FRPFullSizePhotoViewController.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
//
// FRPFullSizePhotoViewController.m
// FRP
//
// Created by Ash Furrow on 10/15/2013.
// Copyright (c) 2013 Ash Furrow. All rights reserved.
//

// View Controllers
#import "FRPFullSizePhotoViewController.h"
#import "FRPPhotoViewController.h"

@interface FRPFullSizePhotoViewController () <UIPageViewControllerDataSource>

// Private assignment
@property (nonatomic, strong) NSArray *photoModelArray;
@property (nonatomic, assign) NSInteger photoIndex;

// Private properties
@property (nonatomic, strong) UIPageViewController *pageViewController;

@end

@implementation FRPFullSizePhotoViewController

-(instancetype)initWithPhotoModels:(NSArray *)photoModelArray currentPhotoIndex:(NSInteger)photoIndex
{
self = [self init];
if (!self) return nil;

// Initialized, read-only properties
self.photoModelArray = photoModelArray;
self.photoIndex = photoIndex;

// View controllers
self.pageViewController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:@{UIPageViewControllerOptionInterPageSpacingKey: @(30)}];
self.pageViewController.dataSource = self;
[self addChildViewController:self.pageViewController];

[self.pageViewController setViewControllers:@[[self photoViewControllerForIndex:photoIndex]] direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];

return self;
}

- (void)viewDidLoad
{
[super viewDidLoad];

// Configure self's view
self.view.backgroundColor = [UIColor blackColor];

// Configure subviews
self.pageViewController.view.frame = self.view.bounds;
[self.view addSubview:self.pageViewController.view];
}

#pragma mark - Private Methods

-(FRPPhotoViewController *)photoViewControllerForIndex:(NSInteger)index {
if (index >= 0 && index < self.photoModelArray.count) {
FRPPhotoModel *photoModel = self.photoModelArray[index];

FRPPhotoViewController *photoViewController = [[FRPPhotoViewController alloc] initWithPhotoModel:photoModel index:index];
return photoViewController;
}

// Index was out of bounds, return nil
return nil;
}

#pragma mark - UIPageViewControllerDataSource Methods

- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(FRPPhotoViewController *)viewController {
return [self photoViewControllerForIndex:viewController.photoIndex - 1];
}

- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(FRPPhotoViewController *)viewController {
return [self photoViewControllerForIndex:viewController.photoIndex + 1];
}

@end
14 changes: 14 additions & 0 deletions FRP/FRPGalleryViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,14 @@
// Copyright (c) 2013 Ash Furrow. All rights reserved.
//

// View Controllers
#import "FRPGalleryViewController.h"
#import "FRPFullSizePhotoViewController.h"

// Views
#import "FRPCell.h"

// Utilities
#import "FRPGalleryFlowLayout.h"
#import "FRPPhotoImporter.h"

Expand Down Expand Up @@ -77,4 +83,12 @@ -(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellF
return cell;
}

#pragma mark - UICollectionViewDelegate Methods

// Note: Can't use rac_signalForSelector: here w/o implementing this method.
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
FRPFullSizePhotoViewController *viewController = [[FRPFullSizePhotoViewController alloc] initWithPhotoModels:self.photosArray currentPhotoIndex:indexPath.item];
[self.navigationController pushViewController:viewController animated:YES];
}

@end
2 changes: 2 additions & 0 deletions FRP/FRPPhotoModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@
@property (nonatomic, strong) NSNumber *rating;
@property (nonatomic, strong) NSString *thumbnailURL;
@property (nonatomic, strong) NSData *thumbnailData;
@property (nonatomic, strong) NSString *fullsizedURL;
@property (nonatomic, strong) NSData *fullsizedData;

@end
20 changes: 20 additions & 0 deletions FRP/FRPPhotoViewController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// FRPPhotoViewController.h
// FRP
//
// Created by Ash Furrow on 10/15/2013.
// Copyright (c) 2013 Ash Furrow. All rights reserved.
//

#import <UIKit/UIKit.h>

@class FRPPhotoModel;

@interface FRPPhotoViewController : UIViewController

-(instancetype)initWithPhotoModel:(FRPPhotoModel *)photoModel index:(NSInteger)photoIndex;

@property (nonatomic, readonly) NSInteger photoIndex;
@property (nonatomic, readonly) FRPPhotoModel *photoModel;

@end
60 changes: 60 additions & 0 deletions FRP/FRPPhotoViewController.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
//
// FRPPhotoViewController.m
// FRP
//
// Created by Ash Furrow on 10/15/2013.
// Copyright (c) 2013 Ash Furrow. All rights reserved.
//

#import "FRPPhotoViewController.h"

// Model
#import "FRPPhotoModel.h"

@interface FRPPhotoViewController ()

// Private assignment
@property (nonatomic, assign) NSInteger photoIndex;
@property (nonatomic, strong) FRPPhotoModel *photoModel;

// Private properties
@property (nonatomic, weak) UIImageView *imageView;

@end

@implementation FRPPhotoViewController

-(instancetype)initWithPhotoModel:(FRPPhotoModel *)photoModel index:(NSInteger)photoIndex
{
self = [self init];
if (!self) return nil;

self.photoModel = photoModel;
self.photoIndex = photoIndex;

return self;
}

- (void)viewDidLoad
{
[super viewDidLoad];

// Configure self's view
self.view.backgroundColor = [UIColor blackColor];

// Configure subviews
UIImageView *imageView = [[UIImageView alloc] initWithFrame:self.view.bounds];
RAC(imageView, image) = [RACObserve(self.photoModel, fullsizedData) map:^id(id value) {
return [UIImage imageWithData:value];
}];
[self.view addSubview:imageView];
self.imageView = imageView;
}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

@end

0 comments on commit 1003257

Please sign in to comment.