This repository has been archived by the owner on Dec 6, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Basics of view controller hierarchy setup.
- Loading branch information
Showing
8 changed files
with
217 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |