From 43c31162a5a8449fd344cc11be8812800eafb2c6 Mon Sep 17 00:00:00 2001 From: Jason Leyrer Date: Fri, 1 Nov 2013 16:57:15 -0500 Subject: [PATCH 1/2] Add background color transitions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit -Add a background image in the app delegate -Add a transitions to move between blue and green background images in each view controller’s viewDidAppear: method. --- ChangingBackground/AppDelegate.h | 2 ++ ChangingBackground/AppDelegate.m | 14 ++++++++---- ChangingBackground/FirstViewController.m | 26 ++++++++++++++++++++++- ChangingBackground/SecondViewController.m | 21 ++++++++++++++++++ 4 files changed, 58 insertions(+), 5 deletions(-) diff --git a/ChangingBackground/AppDelegate.h b/ChangingBackground/AppDelegate.h index f96be1d..84a1eef 100644 --- a/ChangingBackground/AppDelegate.h +++ b/ChangingBackground/AppDelegate.h @@ -10,4 +10,6 @@ @interface AppDelegate : UIResponder +@property (nonatomic, strong) UIImageView *bgImageView; + @end diff --git a/ChangingBackground/AppDelegate.m b/ChangingBackground/AppDelegate.m index 9538cc1..38ac609 100644 --- a/ChangingBackground/AppDelegate.m +++ b/ChangingBackground/AppDelegate.m @@ -14,17 +14,23 @@ @interface AppDelegate () { } @end - @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { - window = [UIWindow.alloc initWithFrame:UIScreen.mainScreen.bounds]; + + window = [UIWindow.alloc initWithFrame:UIScreen.mainScreen.bounds]; [window makeKeyAndVisible]; + self.bgImageView = [[UIImageView alloc] + initWithImage:[UIImage imageNamed:@"blue.png"]]; + + [window addSubview:self.bgImageView]; + FirstViewController *firstViewController = FirstViewController.new; - UINavigationController *navigationController = [UINavigationController.alloc initWithRootViewController:firstViewController]; + UINavigationController *navigationController = + [UINavigationController.alloc initWithRootViewController:firstViewController]; [navigationController setNavigationBarHidden:YES]; - + window.rootViewController = navigationController; return YES; diff --git a/ChangingBackground/FirstViewController.m b/ChangingBackground/FirstViewController.m index 8aedb68..62f80af 100644 --- a/ChangingBackground/FirstViewController.m +++ b/ChangingBackground/FirstViewController.m @@ -8,6 +8,7 @@ #import "FirstViewController.h" #import "SecondViewController.h" +#import "AppDelegate.h" @interface FirstViewController () @@ -15,8 +16,31 @@ @interface FirstViewController () @implementation FirstViewController +- (void)viewDidLoad { + [super viewDidLoad]; + self.view.backgroundColor = [UIColor clearColor]; +} + +- (void)viewDidAppear:(BOOL)animated { + AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] + delegate]; + + // If the background is green, transition to the blue image + if ([delegate.bgImageView.image isEqual:[UIImage imageNamed:@"green.png"]]) { + + [UIView transitionWithView:delegate.bgImageView + duration:1.0f + options:UIViewAnimationOptionTransitionCrossDissolve + animations:^{ + delegate.bgImageView.image = + [UIImage imageNamed:@"blue.png"]; + } + completion:NULL]; + } +} + - (IBAction)goForwardButtonPressed { - SecondViewController *secondViewController = SecondViewController.new; + SecondViewController *secondViewController = SecondViewController.new; [self.navigationController pushViewController:secondViewController animated:YES]; } diff --git a/ChangingBackground/SecondViewController.m b/ChangingBackground/SecondViewController.m index 028f811..7bd1f38 100644 --- a/ChangingBackground/SecondViewController.m +++ b/ChangingBackground/SecondViewController.m @@ -7,10 +7,31 @@ // #import "SecondViewController.h" +#import "AppDelegate.h" @implementation SecondViewController +- (void)viewDidLoad { + [super viewDidLoad]; + self.view.backgroundColor = [UIColor clearColor]; +} + +- (void)viewDidAppear:(BOOL)animated { + AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] + delegate]; + + // Transition to the green background + [UIView transitionWithView:delegate.bgImageView + duration:1.0f + options:UIViewAnimationOptionTransitionCrossDissolve + animations:^{ + delegate.bgImageView.image = + [UIImage imageNamed:@"green.png"]; + } + completion:NULL]; +} + - (IBAction)goBackButtonPressed { [self.navigationController popViewControllerAnimated:YES]; } From 26f213daf3d0fa2dd956b2a889eb6f606507f516 Mon Sep 17 00:00:00 2001 From: Jason Leyrer Date: Fri, 1 Nov 2013 16:58:06 -0500 Subject: [PATCH 2/2] Make the xibs look like the demo. --- ChangingBackground/FirstViewController.xib | 258 +++--------------- ChangingBackground/SecondViewController.xib | 284 +++----------------- 2 files changed, 82 insertions(+), 460 deletions(-) diff --git a/ChangingBackground/FirstViewController.xib b/ChangingBackground/FirstViewController.xib index 0dd58c2..d080ed5 100644 --- a/ChangingBackground/FirstViewController.xib +++ b/ChangingBackground/FirstViewController.xib @@ -1,217 +1,41 @@ - - - - 1552 - 12C3006 - 3084 - 1187.34 - 625.00 - - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - 2083 - - - IBProxyObject - IBUIButton - IBUILabel - IBUIView - - - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - - - PluginDependencyRecalculationVersion - - - - - IBFilesOwner - IBCocoaTouchFramework - - - IBFirstResponder - IBCocoaTouchFramework - - - - 274 - - - - 292 - {{77, 115}, {166, 21}} - - - _NS:9 - NO - YES - 7 - NO - IBCocoaTouchFramework - Home View Controller - - 1 - MCAwIDAAA - darkTextColor - - - 0 - - 1 - 17 - - - Helvetica - 17 - 16 - - NO - - - - 292 - {{102, 180}, {109, 44}} - - _NS:9 - NO - IBCocoaTouchFramework - 0 - 0 - 1 - Go Forward - - 3 - MQA - - - 1 - MC4xOTYwNzg0MzQ2IDAuMzA5ODAzOTMyOSAwLjUyMTU2ODY1NgA - - - 3 - MC41AA - - - 2 - 15 - - - Helvetica-Bold - 15 - 16 - - - - {{0, 20}, {320, 548}} - - - 3 - MQA - - 2 - - - - - IBUIScreenMetrics - - YES - - - - - - {320, 568} - {568, 320} - - - IBCocoaTouchFramework - Retina 4 Full Screen - 2 - - IBCocoaTouchFramework - - - - - - - view - - - - 3 - - - - goForwardButtonPressed - - - 7 - - 8 - - - - - - 0 - - - - - - 1 - - - - - - - - - -1 - - - File's Owner - - - -2 - - - - - 4 - - - - - 7 - - - - - - - FirstViewController - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - UIResponder - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - - - - - - 8 - - - 0 - IBCocoaTouchFramework - YES - 3 - 2083 - - + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ChangingBackground/SecondViewController.xib b/ChangingBackground/SecondViewController.xib index d603949..c83d08f 100644 --- a/ChangingBackground/SecondViewController.xib +++ b/ChangingBackground/SecondViewController.xib @@ -1,243 +1,41 @@ - - - - 1552 - 12C3006 - 3084 - 1187.34 - 625.00 - - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - 2083 - - - IBProxyObject - IBUIButton - IBUILabel - IBUIView - - - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - - - PluginDependencyRecalculationVersion - - - - - IBFilesOwner - IBCocoaTouchFramework - - - IBFirstResponder - IBCocoaTouchFramework - - - - 274 - - - - 292 - {{71, 118}, {209, 21}} - - - - _NS:9 - NO - YES - 7 - NO - IBCocoaTouchFramework - Second View Controller - - 1 - MCAwIDAAA - darkTextColor - - - 0 - - 1 - 17 - - - Helvetica - 17 - 16 - - NO - - - - 292 - {{118, 178}, {85, 44}} - - - _NS:9 - NO - IBCocoaTouchFramework - 0 - 0 - 1 - Go Back - - 3 - MQA - - - 1 - MC4xOTYwNzg0MzQ2IDAuMzA5ODAzOTMyOSAwLjUyMTU2ODY1NgA - - - 3 - MC41AA - - - 2 - 15 - - - Helvetica-Bold - 15 - 16 - - - - {{0, 20}, {320, 548}} - - - - - 3 - MQA - - 2 - - - - - IBUIScreenMetrics - - YES - - - - - - {320, 568} - {568, 320} - - - IBCocoaTouchFramework - Retina 4 Full Screen - 2 - - IBCocoaTouchFramework - - - - - - - view - - - - 3 - - - - goBackButtonPressed - - - 7 - - 10 - - - - - - 0 - - - - - - 1 - - - - - - - - - -1 - - - File's Owner - - - -2 - - - - - 4 - - - - - 7 - - - - - - - SecondViewController - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - UIResponder - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - - - - - - 10 - - - - - SecondViewController - UIViewController - - goBackButtonPressed - id - - - goBackButtonPressed - - goBackButtonPressed - id - - - - IBProjectSource - ./Classes/SecondViewController.h - - - - - 0 - IBCocoaTouchFramework - YES - 3 - 2083 - - + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file