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
15 changes: 15 additions & 0 deletions ChangingBackground.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
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 */; };
AD8A1488191B0508000F8002 /* MyNavigationController.m in Sources */ = {isa = PBXBuildFile; fileRef = AD8A1487191B0508000F8002 /* MyNavigationController.m */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand All @@ -50,6 +51,8 @@
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>"; };
AD8A1486191B0508000F8002 /* MyNavigationController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MyNavigationController.h; sourceTree = "<group>"; };
AD8A1487191B0508000F8002 /* MyNavigationController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MyNavigationController.m; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -98,6 +101,7 @@
children = (
001809EF171C6768002D3E93 /* BackgroundImages */,
001809D5171C63FC002D3E93 /* AppDelegate */,
AD8A1489191B0512000F8002 /* NavigationController */,
001809DC171C6453002D3E93 /* ViewControllers */,
001809BF171C637E002D3E93 /* Supporting Files */,
);
Expand Down Expand Up @@ -167,6 +171,15 @@
name = BackgroundImages;
sourceTree = "<group>";
};
AD8A1489191B0512000F8002 /* NavigationController */ = {
isa = PBXGroup;
children = (
AD8A1486191B0508000F8002 /* MyNavigationController.h */,
AD8A1487191B0508000F8002 /* MyNavigationController.m */,
);
name = NavigationController;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
Expand Down Expand Up @@ -242,6 +255,7 @@
001809C9171C637E002D3E93 /* AppDelegate.m in Sources */,
001809D9171C6448002D3E93 /* FirstViewController.m in Sources */,
001809E0171C64E4002D3E93 /* SecondViewController.m in Sources */,
AD8A1488191B0508000F8002 /* MyNavigationController.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -356,6 +370,7 @@
001809D4171C637E002D3E93 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
Expand Down
39 changes: 33 additions & 6 deletions ChangingBackground/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,53 @@

#import "AppDelegate.h"
#import "FirstViewController.h"
#import "MyNavigationController.h"

@interface AppDelegate () {
@interface AppDelegate ()<UINavigationControllerDelegate>
{
UIWindow *window;
MyNavigationController *navController;
}
@end


@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
- (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;
navController = [MyNavigationController.alloc initWithRootViewController:firstViewController];
[navController setNavigationBarHidden:YES];
window.rootViewController = navController;
navController.delegate = self;
navController.imageView = [UIImageView.alloc initWithFrame:UIScreen.mainScreen.bounds];
navController.imageView.image = [UIImage imageNamed:@"blue.png"];
[navController.view insertSubview:navController.imageView atIndex:0];

return YES;
}

-(void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
[navController backgroundCheck];
}

-(id<UIViewControllerAnimatedTransitioning>)navigationController:(UINavigationController *)navigationController animationControllerForOperation:(UINavigationControllerOperation)operation fromViewController:(UIViewController *)fromVC toViewController:(UIViewController *)toVC
{
if (operation == UINavigationControllerOperationPush)
{
[UIView animateWithDuration:.25 animations:^{
fromVC.view.frame = CGRectMake(-320, 0, fromVC.view.frame.size.width, fromVC.view.frame.size.height);
}];
}
return nil;
}





@end
12 changes: 11 additions & 1 deletion ChangingBackground/FirstViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,22 @@
#import "SecondViewController.h"

@interface FirstViewController ()
{
UIImageView *imageView;
}

@end

@implementation FirstViewController

- (IBAction)goForwardButtonPressed {
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
self.view.backgroundColor = [UIColor clearColor];
}

- (IBAction)goForwardButtonPressed
{
SecondViewController *secondViewController = SecondViewController.new;
[self.navigationController pushViewController:secondViewController animated:YES];
}
Expand Down
16 changes: 16 additions & 0 deletions ChangingBackground/MyNavigationController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// MyNavigationController.h
// ChangingBackground
//
// Created by Calvin Hildreth on 5/7/14.
// Copyright (c) 2014 Ora Interactive. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface MyNavigationController : UINavigationController
@property (strong, nonatomic) UIImageView *imageView;

-(void)backgroundCheck;
-(void)changeBackgroundWithImageNamed:(NSString *)imageName;
@end
48 changes: 48 additions & 0 deletions ChangingBackground/MyNavigationController.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//
// MyNavigationController.m
// ChangingBackground
//
// Created by Calvin Hildreth on 5/7/14.
// Copyright (c) 2014 Ora Interactive. All rights reserved.
//

#import "MyNavigationController.h"

@interface MyNavigationController ()

@end

@implementation MyNavigationController

-(void)backgroundCheck
{
NSString *imageName;
switch (self.viewControllers.count)
{
case 1:
imageName = @"blue.png";
[self changeBackgroundWithImageNamed:imageName];
break;

case 2:
imageName = @"green.png";
[self changeBackgroundWithImageNamed:imageName];
break;

default:
break;
}
}

-(void)changeBackgroundWithImageNamed:(NSString *)imageName
{
[UIView transitionWithView:self.view
duration:2
options:UIViewAnimationOptionTransitionCrossDissolve
animations:^{
self.imageView.image = [UIImage imageNamed:imageName];
}
completion:NULL];
}

@end
10 changes: 8 additions & 2 deletions ChangingBackground/SecondViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,16 @@

#import "SecondViewController.h"


@implementation SecondViewController

- (IBAction)goBackButtonPressed {
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
self.view.backgroundColor = [UIColor clearColor];
}

- (IBAction)goBackButtonPressed
{
[self.navigationController popViewControllerAnimated:YES];
}

Expand Down