Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions ChangingBackground.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@
001809CD171C637E002D3E93 /* Default@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 001809CC171C637E002D3E93 /* Default@2x.png */; };
001809CF171C637E002D3E93 /* Default-568h@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 001809CE171C637E002D3E93 /* Default-568h@2x.png */; };
001809D9171C6448002D3E93 /* FirstViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 001809D7171C6448002D3E93 /* FirstViewController.m */; };
001809DA171C6448002D3E93 /* FirstViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 001809D8171C6448002D3E93 /* FirstViewController.xib */; };
001809E0171C64E4002D3E93 /* SecondViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 001809DE171C64E3002D3E93 /* SecondViewController.m */; };
001809E1171C64E4002D3E93 /* SecondViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 001809DF171C64E3002D3E93 /* SecondViewController.xib */; };
001809EB171C6764002D3E93 /* blue.png in Resources */ = {isa = PBXBuildFile; fileRef = 001809E7171C6764002D3E93 /* blue.png */; };
001809EC171C6764002D3E93 /* blue@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 001809E8171C6764002D3E93 /* blue@2x.png */; };
001809ED171C6764002D3E93 /* green.png in Resources */ = {isa = PBXBuildFile; fileRef = 001809E9171C6764002D3E93 /* green.png */; };
001809EE171C6764002D3E93 /* green@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 001809EA171C6764002D3E93 /* green@2x.png */; };
5D7EB6A31954A76900AD7E76 /* MainStoryboard.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 5D7EB6A21954A76900AD7E76 /* MainStoryboard.storyboard */; };
5D7EB6A91954ADF300AD7E76 /* AEMCollectionVC.m in Sources */ = {isa = PBXBuildFile; fileRef = 5D7EB6A81954ADF300AD7E76 /* AEMCollectionVC.m */; };
5D7EB6AC1954AE3800AD7E76 /* AEMViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 5D7EB6AB1954AE3800AD7E76 /* AEMViewController.m */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand All @@ -42,14 +43,17 @@
001809CE171C637E002D3E93 /* Default-568h@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Default-568h@2x.png"; sourceTree = "<group>"; };
001809D6171C6448002D3E93 /* FirstViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FirstViewController.h; sourceTree = "<group>"; };
001809D7171C6448002D3E93 /* FirstViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FirstViewController.m; sourceTree = "<group>"; };
001809D8171C6448002D3E93 /* FirstViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = FirstViewController.xib; sourceTree = "<group>"; };
001809DD171C64E3002D3E93 /* SecondViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SecondViewController.h; sourceTree = "<group>"; };
001809DE171C64E3002D3E93 /* SecondViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SecondViewController.m; sourceTree = "<group>"; };
001809DF171C64E3002D3E93 /* SecondViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = SecondViewController.xib; sourceTree = "<group>"; };
001809E7171C6764002D3E93 /* blue.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = blue.png; sourceTree = "<group>"; };
001809E8171C6764002D3E93 /* blue@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "blue@2x.png"; sourceTree = "<group>"; };
001809E9171C6764002D3E93 /* green.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = green.png; sourceTree = "<group>"; };
001809EA171C6764002D3E93 /* green@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "green@2x.png"; sourceTree = "<group>"; };
5D7EB6A21954A76900AD7E76 /* MainStoryboard.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = MainStoryboard.storyboard; sourceTree = "<group>"; };
5D7EB6A71954ADF300AD7E76 /* AEMCollectionVC.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AEMCollectionVC.h; sourceTree = "<group>"; };
5D7EB6A81954ADF300AD7E76 /* AEMCollectionVC.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AEMCollectionVC.m; sourceTree = "<group>"; };
5D7EB6AA1954AE3800AD7E76 /* AEMViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AEMViewController.h; sourceTree = "<group>"; };
5D7EB6AB1954AE3800AD7E76 /* AEMViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AEMViewController.m; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand All @@ -69,6 +73,7 @@
001809AC171C637E002D3E93 = {
isa = PBXGroup;
children = (
5D7EB6A21954A76900AD7E76 /* MainStoryboard.storyboard */,
001809BE171C637E002D3E93 /* ChangingBackground */,
001809B7171C637E002D3E93 /* Frameworks */,
001809B6171C637E002D3E93 /* Products */,
Expand Down Expand Up @@ -132,7 +137,6 @@
children = (
001809D6171C6448002D3E93 /* FirstViewController.h */,
001809D7171C6448002D3E93 /* FirstViewController.m */,
001809D8171C6448002D3E93 /* FirstViewController.xib */,
);
name = FirstViewController;
sourceTree = "<group>";
Expand All @@ -142,6 +146,10 @@
children = (
001809DB171C644A002D3E93 /* FirstViewController */,
001809E2171C650E002D3E93 /* SecondViewController */,
5D7EB6A71954ADF300AD7E76 /* AEMCollectionVC.h */,
5D7EB6A81954ADF300AD7E76 /* AEMCollectionVC.m */,
5D7EB6AA1954AE3800AD7E76 /* AEMViewController.h */,
5D7EB6AB1954AE3800AD7E76 /* AEMViewController.m */,
);
name = ViewControllers;
sourceTree = "<group>";
Expand All @@ -151,7 +159,6 @@
children = (
001809DD171C64E3002D3E93 /* SecondViewController.h */,
001809DE171C64E3002D3E93 /* SecondViewController.m */,
001809DF171C64E3002D3E93 /* SecondViewController.xib */,
);
name = SecondViewController;
sourceTree = "<group>";
Expand Down Expand Up @@ -219,11 +226,10 @@
buildActionMask = 2147483647;
files = (
001809C3171C637E002D3E93 /* InfoPlist.strings in Resources */,
5D7EB6A31954A76900AD7E76 /* MainStoryboard.storyboard in Resources */,
001809CB171C637E002D3E93 /* Default.png in Resources */,
001809CD171C637E002D3E93 /* Default@2x.png in Resources */,
001809CF171C637E002D3E93 /* Default-568h@2x.png in Resources */,
001809DA171C6448002D3E93 /* FirstViewController.xib in Resources */,
001809E1171C64E4002D3E93 /* SecondViewController.xib in Resources */,
001809EB171C6764002D3E93 /* blue.png in Resources */,
001809EC171C6764002D3E93 /* blue@2x.png in Resources */,
001809ED171C6764002D3E93 /* green.png in Resources */,
Expand All @@ -238,9 +244,11 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
5D7EB6A91954ADF300AD7E76 /* AEMCollectionVC.m in Sources */,
001809C5171C637E002D3E93 /* main.m in Sources */,
001809C9171C637E002D3E93 /* AppDelegate.m in Sources */,
001809D9171C6448002D3E93 /* FirstViewController.m in Sources */,
5D7EB6AC1954AE3800AD7E76 /* AEMViewController.m in Sources */,
001809E0171C64E4002D3E93 /* SecondViewController.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -356,6 +364,7 @@
001809D4171C637E002D3E93 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
Expand Down
22 changes: 22 additions & 0 deletions ChangingBackground/AEMCollectionVC.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// AEMCollectionVC.h
// ChangingBackground
//
// Created by Arthur Mayes on 6/20/14.
// Copyright (c) 2014 Ora Interactive. All rights reserved.
//

#import <UIKit/UIKit.h>

@protocol AEMCollectionVCDelegate <NSObject>

- (void)didGoToFirst;
- (void)didGoToSecond;

@end

@interface AEMCollectionVC : UICollectionViewController

@property (nonatomic, weak) id<AEMCollectionVCDelegate> delegate;

@end
89 changes: 89 additions & 0 deletions ChangingBackground/AEMCollectionVC.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
//
// AEMCollectionVC.m
// ChangingBackground
//
// Created by Arthur Mayes on 6/20/14.
// Copyright (c) 2014 Ora Interactive. All rights reserved.
//

#import "AEMCollectionVC.h"
#import "FirstViewController.h"
#import "SecondViewController.h"

@interface AEMCollectionVC () <FirstViewControllerDelegate, SecondViewControllerDelegate>

@property (nonatomic, weak) FirstViewController *firstViewController;
@property (nonatomic, weak) SecondViewController *secondViewController;

@end

@implementation AEMCollectionVC

#pragma mark - Lazy Instantiation

- (FirstViewController *)firstViewController
{
if (!_firstViewController) {
_firstViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"First"];
_firstViewController.delegate = self;
[_firstViewController willMoveToParentViewController:self];
[self addChildViewController:_firstViewController];
}
return _firstViewController;
}

- (SecondViewController *)secondViewController
{
if (!_secondViewController) {
_secondViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"Second"];
_secondViewController.delegate = self;
[_secondViewController willMoveToParentViewController:self];
[self addChildViewController:_secondViewController];
}
return _secondViewController;
}

#pragma mark - Delegate Methods

- (void)segueToFirst
{
NSIndexPath *indexPath = [NSIndexPath indexPathForItem:0 inSection:0];
[self.collectionView scrollToItemAtIndexPath:indexPath atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally animated:YES];
if ([self.delegate respondsToSelector:@selector(didGoToFirst)]) {
[self.delegate didGoToFirst];
}
}

- (void)segueToSecond
{
NSIndexPath *indexPath = [NSIndexPath indexPathForItem:1 inSection:0];
[self.collectionView scrollToItemAtIndexPath:indexPath atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally animated:YES];
if ([self.delegate respondsToSelector:@selector(didGoToSecond)]) {
[self.delegate didGoToSecond];
}
}

#pragma mark - UICollectionView Delegate/DataSource

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return 2;
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath];

NSArray *array = @[@"firstViewController", @"secondViewController"];

UIViewController *viewController = [self valueForKey:array[indexPath.item]];

[cell.contentView addSubview:viewController.view];

// There would be some additional work to do here if there were more than two VCs
// But I would have used a navigation controller if there were more than two VCs

return cell;
}

@end
13 changes: 13 additions & 0 deletions ChangingBackground/AEMViewController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// AEMViewController.h
// ChangingBackground
//
// Created by Arthur Mayes on 6/20/14.
// Copyright (c) 2014 Ora Interactive. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface AEMViewController : UIViewController

@end
74 changes: 74 additions & 0 deletions ChangingBackground/AEMViewController.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
//
// AEMViewController.m
// ChangingBackground
//
// Created by Arthur Mayes on 6/20/14.
// Copyright (c) 2014 Ora Interactive. All rights reserved.
//

#import "AEMViewController.h"
#import "AEMCollectionVC.h"

@interface AEMViewController () <AEMCollectionVCDelegate>
@property (weak, nonatomic) IBOutlet UIImageView *protectiveView;
@property (weak, nonatomic) IBOutlet UIImageView *blueImageView;
@property (weak, nonatomic) IBOutlet UIImageView *greenImageView;

@end

@implementation AEMViewController

#pragma mark - View Life Cycle

- (void)viewDidLoad
{
[super viewDidLoad];
[self.protectiveView setImage:[UIImage imageNamed:@"blue"]];
[self.blueImageView setImage:[UIImage imageNamed:@"blue"]];
[self.greenImageView setImage:[UIImage imageNamed:@"green"]];
}

#pragma mark - Background Animations

- (void)didGoToFirst
{
// Protective view is in case of quick-fire button tapping
[self.protectiveView setImage:[UIImage imageNamed:@"green"]];
[self.blueImageView setAlpha:0.0];
[self.view sendSubviewToBack:self.greenImageView];
[self.view sendSubviewToBack:self.protectiveView];

// Not using weakSelf here, because this is the rootVC
[UIView animateWithDuration:0.7 delay:0.2 options:UIViewAnimationOptionCurveEaseIn animations:^{
[self.blueImageView setAlpha:1.0f];
} completion:nil];

}

- (void)didGoToSecond
{
// Protective view is in case of quick-fire button tapping
[self.protectiveView setImage:[UIImage imageNamed:@"blue"]];
[self.greenImageView setAlpha:0.0];
[self.view sendSubviewToBack:self.blueImageView];
[self.view sendSubviewToBack:self.protectiveView];

// Not using weakSelf here, because this is the rootVC
[UIView animateWithDuration:0.7 delay:0.2 options:UIViewAnimationOptionCurveEaseIn animations:^{
[self.greenImageView setAlpha:1.0f];
} completion:nil];

}

#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"toCollection"]) {
AEMCollectionVC *collectionVC = (AEMCollectionVC *)[segue destinationViewController];
collectionVC.delegate = self;
}
}

@end
2 changes: 2 additions & 0 deletions ChangingBackground/AppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;

@end
11 changes: 1 addition & 10 deletions ChangingBackground/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,14 @@
#import "AppDelegate.h"
#import "FirstViewController.h"

@interface AppDelegate () {
UIWindow *window;
}
@interface AppDelegate ()
@end


@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
window = [UIWindow.alloc initWithFrame:UIScreen.mainScreen.bounds];
[window makeKeyAndVisible];

FirstViewController *firstViewController = FirstViewController.new;
UINavigationController *navigationController = [UINavigationController.alloc initWithRootViewController:firstViewController];
[navigationController setNavigationBarHidden:YES];

window.rootViewController = navigationController;

return YES;
}
Expand Down
4 changes: 2 additions & 2 deletions ChangingBackground/ChangingBackground-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@
<string>1.0</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UIMainStoryboardFile</key>
<string>MainStoryboard</string>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
</dict>
</plist>
9 changes: 9 additions & 0 deletions ChangingBackground/FirstViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,17 @@

#import <UIKit/UIKit.h>

@protocol FirstViewControllerDelegate <NSObject>

@optional
- (void)segueToSecond;

@end

@interface FirstViewController : UIViewController

@property (nonatomic, weak) id<FirstViewControllerDelegate> delegate;

- (IBAction)goForwardButtonPressed;

@end
8 changes: 5 additions & 3 deletions ChangingBackground/FirstViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ @interface FirstViewController ()

@implementation FirstViewController

- (IBAction)goForwardButtonPressed {
SecondViewController *secondViewController = SecondViewController.new;
[self.navigationController pushViewController:secondViewController animated:YES];
- (IBAction)goForwardButtonPressed
{
if ([self.delegate respondsToSelector:@selector(segueToSecond)]) {
[self.delegate segueToSecond];
}
}

@end
Loading