diff --git a/ChangingBackground.xcodeproj/project.pbxproj b/ChangingBackground.xcodeproj/project.pbxproj index 2e16be1..2a750ab 100644 --- a/ChangingBackground.xcodeproj/project.pbxproj +++ b/ChangingBackground.xcodeproj/project.pbxproj @@ -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 */ @@ -50,6 +51,8 @@ 001809E8171C6764002D3E93 /* blue@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "blue@2x.png"; sourceTree = ""; }; 001809E9171C6764002D3E93 /* green.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = green.png; sourceTree = ""; }; 001809EA171C6764002D3E93 /* green@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "green@2x.png"; sourceTree = ""; }; + AD8A1486191B0508000F8002 /* MyNavigationController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MyNavigationController.h; sourceTree = ""; }; + AD8A1487191B0508000F8002 /* MyNavigationController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MyNavigationController.m; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -98,6 +101,7 @@ children = ( 001809EF171C6768002D3E93 /* BackgroundImages */, 001809D5171C63FC002D3E93 /* AppDelegate */, + AD8A1489191B0512000F8002 /* NavigationController */, 001809DC171C6453002D3E93 /* ViewControllers */, 001809BF171C637E002D3E93 /* Supporting Files */, ); @@ -167,6 +171,15 @@ name = BackgroundImages; sourceTree = ""; }; + AD8A1489191B0512000F8002 /* NavigationController */ = { + isa = PBXGroup; + children = ( + AD8A1486191B0508000F8002 /* MyNavigationController.h */, + AD8A1487191B0508000F8002 /* MyNavigationController.m */, + ); + name = NavigationController; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -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; }; @@ -356,6 +370,7 @@ 001809D4171C637E002D3E93 /* Release */, ); defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; }; /* End XCConfigurationList section */ }; diff --git a/ChangingBackground/AppDelegate.m b/ChangingBackground/AppDelegate.m index 9538cc1..43901b6 100644 --- a/ChangingBackground/AppDelegate.m +++ b/ChangingBackground/AppDelegate.m @@ -8,26 +8,53 @@ #import "AppDelegate.h" #import "FirstViewController.h" +#import "MyNavigationController.h" -@interface AppDelegate () { +@interface AppDelegate () +{ 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)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 diff --git a/ChangingBackground/FirstViewController.m b/ChangingBackground/FirstViewController.m index 8aedb68..4fa1aba 100644 --- a/ChangingBackground/FirstViewController.m +++ b/ChangingBackground/FirstViewController.m @@ -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]; } diff --git a/ChangingBackground/MyNavigationController.h b/ChangingBackground/MyNavigationController.h new file mode 100644 index 0000000..99e638e --- /dev/null +++ b/ChangingBackground/MyNavigationController.h @@ -0,0 +1,16 @@ +// +// MyNavigationController.h +// ChangingBackground +// +// Created by Calvin Hildreth on 5/7/14. +// Copyright (c) 2014 Ora Interactive. All rights reserved. +// + +#import + +@interface MyNavigationController : UINavigationController +@property (strong, nonatomic) UIImageView *imageView; + +-(void)backgroundCheck; +-(void)changeBackgroundWithImageNamed:(NSString *)imageName; +@end diff --git a/ChangingBackground/MyNavigationController.m b/ChangingBackground/MyNavigationController.m new file mode 100644 index 0000000..6c91b55 --- /dev/null +++ b/ChangingBackground/MyNavigationController.m @@ -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 diff --git a/ChangingBackground/SecondViewController.m b/ChangingBackground/SecondViewController.m index 028f811..4a3ebf3 100644 --- a/ChangingBackground/SecondViewController.m +++ b/ChangingBackground/SecondViewController.m @@ -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]; }