diff --git a/ChangingBackground.xcodeproj/project.pbxproj b/ChangingBackground.xcodeproj/project.pbxproj index 2e16be1..56c5387 100644 --- a/ChangingBackground.xcodeproj/project.pbxproj +++ b/ChangingBackground.xcodeproj/project.pbxproj @@ -24,6 +24,8 @@ 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 */; }; + 67B6165F1912C21100E08AC1 /* UINavigationController+CustomTransition.m in Sources */ = {isa = PBXBuildFile; fileRef = 67B6165E1912C21100E08AC1 /* UINavigationController+CustomTransition.m */; }; + 67B616631912C3D100E08AC1 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 67B616621912C3D100E08AC1 /* QuartzCore.framework */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -50,6 +52,9 @@ 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 = ""; }; + 67B6165D1912C21100E08AC1 /* UINavigationController+CustomTransition.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UINavigationController+CustomTransition.h"; sourceTree = ""; }; + 67B6165E1912C21100E08AC1 /* UINavigationController+CustomTransition.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UINavigationController+CustomTransition.m"; sourceTree = ""; }; + 67B616621912C3D100E08AC1 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -57,6 +62,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 67B616631912C3D100E08AC1 /* QuartzCore.framework in Frameworks */, 001809B9171C637E002D3E93 /* UIKit.framework in Frameworks */, 001809BB171C637E002D3E93 /* Foundation.framework in Frameworks */, 001809BD171C637E002D3E93 /* CoreGraphics.framework in Frameworks */, @@ -86,6 +92,7 @@ 001809B7171C637E002D3E93 /* Frameworks */ = { isa = PBXGroup; children = ( + 67B616621912C3D100E08AC1 /* QuartzCore.framework */, 001809B8171C637E002D3E93 /* UIKit.framework */, 001809BA171C637E002D3E93 /* Foundation.framework */, 001809BC171C637E002D3E93 /* CoreGraphics.framework */, @@ -96,6 +103,7 @@ 001809BE171C637E002D3E93 /* ChangingBackground */ = { isa = PBXGroup; children = ( + 67B6165C1912C1A100E08AC1 /* Categories */, 001809EF171C6768002D3E93 /* BackgroundImages */, 001809D5171C63FC002D3E93 /* AppDelegate */, 001809DC171C6453002D3E93 /* ViewControllers */, @@ -167,6 +175,15 @@ name = BackgroundImages; sourceTree = ""; }; + 67B6165C1912C1A100E08AC1 /* Categories */ = { + isa = PBXGroup; + children = ( + 67B6165D1912C21100E08AC1 /* UINavigationController+CustomTransition.h */, + 67B6165E1912C21100E08AC1 /* UINavigationController+CustomTransition.m */, + ); + name = Categories; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -241,6 +258,7 @@ 001809C5171C637E002D3E93 /* main.m in Sources */, 001809C9171C637E002D3E93 /* AppDelegate.m in Sources */, 001809D9171C6448002D3E93 /* FirstViewController.m in Sources */, + 67B6165F1912C21100E08AC1 /* UINavigationController+CustomTransition.m in Sources */, 001809E0171C64E4002D3E93 /* SecondViewController.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -356,6 +374,7 @@ 001809D4171C637E002D3E93 /* Release */, ); defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; }; /* End XCConfigurationList section */ }; diff --git a/ChangingBackground/AppDelegate.h b/ChangingBackground/AppDelegate.h index f96be1d..408b00f 100644 --- a/ChangingBackground/AppDelegate.h +++ b/ChangingBackground/AppDelegate.h @@ -10,4 +10,7 @@ @interface AppDelegate : UIResponder +- (void)fadeFromBlueToGreenImage; +- (void)fadeFromGreenToBlueImage; + @end diff --git a/ChangingBackground/AppDelegate.m b/ChangingBackground/AppDelegate.m index 9538cc1..9259c73 100644 --- a/ChangingBackground/AppDelegate.m +++ b/ChangingBackground/AppDelegate.m @@ -12,6 +12,11 @@ @interface AppDelegate () { UIWindow *window; } + +//These UIImageView properties will be added as subviews of window +@property (nonatomic, strong) UIImageView* blueBGImageView; +@property (nonatomic, strong) UIImageView* greenBGImageView; + @end @@ -21,7 +26,21 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:( window = [UIWindow.alloc initWithFrame:UIScreen.mainScreen.bounds]; [window makeKeyAndVisible]; + //Adding an imageView with the Green image as a subview of window + self.greenBGImageView = [[UIImageView alloc]initWithFrame:[[UIScreen mainScreen] bounds]]; + [self.greenBGImageView setImage:[UIImage imageNamed:@"green.png"]]; + [window addSubview:self.greenBGImageView]; + + //Adding an imageView with the Blue image as a subview of window (on top of greenImageView) + self.blueBGImageView = [[UIImageView alloc]initWithFrame:[[UIScreen mainScreen] bounds]]; + [self.blueBGImageView setImage:[UIImage imageNamed:@"blue.png"]]; + [window addSubview:self.blueBGImageView]; + FirstViewController *firstViewController = FirstViewController.new; + + //Making the background color of FirstViewController clearColor so that the imageViews added as subviews of window can be seen. + [firstViewController.view setBackgroundColor:[UIColor clearColor]]; + UINavigationController *navigationController = [UINavigationController.alloc initWithRootViewController:firstViewController]; [navigationController setNavigationBarHidden:YES]; @@ -30,4 +49,30 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:( return YES; } +// UIView animation changes the alpha of the blueImageView from current value to 0.0 (fully transparent) +// This reveals the greenImageView behind the blueImageView +- (void)fadeFromBlueToGreenImage +{ + [UIView animateWithDuration:2.5 + delay:0.0 + options:UIViewAnimationOptionBeginFromCurrentState + animations:^{ + self.blueBGImageView.alpha = 0.0; + } + completion:nil]; +} + +// UIView animation changes the alpha of the blueImageView from current value to 1.0 (fully opaque) +// This hides the greenImageView behind the blueImageView +- (void)fadeFromGreenToBlueImage +{ + [UIView animateWithDuration:2.5 + delay:0.0 + options:UIViewAnimationOptionBeginFromCurrentState + animations:^{ + self.blueBGImageView.alpha = 1.0; + } + completion:nil]; +} + @end diff --git a/ChangingBackground/ChangingBackground-Prefix.pch b/ChangingBackground/ChangingBackground-Prefix.pch index 4a89986..9b44dc7 100644 --- a/ChangingBackground/ChangingBackground-Prefix.pch +++ b/ChangingBackground/ChangingBackground-Prefix.pch @@ -11,4 +11,8 @@ #ifdef __OBJC__ #import #import + #import "AppDelegate.h" #endif + +//Adding a Macro to access the AppDelegate easily in other programs +#define APPDELEGATE ((AppDelegate*)[[UIApplication sharedApplication] delegate]) diff --git a/ChangingBackground/FirstViewController.m b/ChangingBackground/FirstViewController.m index 8aedb68..06f9e7e 100644 --- a/ChangingBackground/FirstViewController.m +++ b/ChangingBackground/FirstViewController.m @@ -8,6 +8,7 @@ #import "FirstViewController.h" #import "SecondViewController.h" +#import "UINavigationController+CustomTransition.h" @interface FirstViewController () @@ -17,7 +18,11 @@ @implementation FirstViewController - (IBAction)goForwardButtonPressed { SecondViewController *secondViewController = SecondViewController.new; - [self.navigationController pushViewController:secondViewController animated:YES]; + + //Using the customTransiton method from UINavigationController's CustomTransition category + [self.navigationController pushViewControllerWithCustomTansition:secondViewController]; + + [APPDELEGATE fadeFromBlueToGreenImage]; } @end diff --git a/ChangingBackground/FirstViewController.xib b/ChangingBackground/FirstViewController.xib index 0dd58c2..824cb81 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 - - + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ChangingBackground/SecondViewController.m b/ChangingBackground/SecondViewController.m index 028f811..b0716b1 100644 --- a/ChangingBackground/SecondViewController.m +++ b/ChangingBackground/SecondViewController.m @@ -7,12 +7,14 @@ // #import "SecondViewController.h" - +#import "UINavigationController+CustomTransition.h" @implementation SecondViewController - (IBAction)goBackButtonPressed { - [self.navigationController popViewControllerAnimated:YES]; + //Using the customTransiton method from UINavigationController's CustomTransition category + [self.navigationController popViewControllerWithCustomTansition]; + [APPDELEGATE fadeFromGreenToBlueImage]; } @end diff --git a/ChangingBackground/SecondViewController.xib b/ChangingBackground/SecondViewController.xib index d603949..a36dd07 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 - - + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ChangingBackground/UINavigationController+CustomTransition.h b/ChangingBackground/UINavigationController+CustomTransition.h new file mode 100644 index 0000000..0502fdb --- /dev/null +++ b/ChangingBackground/UINavigationController+CustomTransition.h @@ -0,0 +1,16 @@ +// +// UINavigationController+CustomTransition.h +// ChangingBackground +// +// Created by Jomis Kakozhayil on 01/05/14. +// Copyright (c) 2014 Ora Interactive. All rights reserved. +// + +#import + +@interface UINavigationController (CustomTransition) + +- (void)pushViewControllerWithCustomTansition:(UIViewController *)viewController; +- (void)popViewControllerWithCustomTansition; + +@end diff --git a/ChangingBackground/UINavigationController+CustomTransition.m b/ChangingBackground/UINavigationController+CustomTransition.m new file mode 100644 index 0000000..92ea3da --- /dev/null +++ b/ChangingBackground/UINavigationController+CustomTransition.m @@ -0,0 +1,43 @@ +// +// UINavigationController+CustomTransition.m +// ChangingBackground +// +// Created by Jomis Kakozhayil on 01/05/14. +// Copyright (c) 2014 Ora Interactive. All rights reserved. +// + +#import "UINavigationController+CustomTransition.h" + +@implementation UINavigationController (CustomTransition) + +- (void)pushViewControllerWithCustomTansition:(UIViewController *)viewController +{ + CATransition *transition = [CATransition animation]; + + transition.duration = 0.25; + transition.type = kCATransitionPush; + transition.subtype = kCATransitionFromRight; + + transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; + + [self.view.layer addAnimation:transition forKey:@"customTransitionPush"]; + + [self pushViewController:viewController animated:NO]; +} + +- (void)popViewControllerWithCustomTansition +{ + CATransition *transition = [CATransition animation]; + + transition.duration = 0.25; + transition.type = kCATransitionPush; + transition.subtype = kCATransitionFromLeft; + + transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; + + [self.view.layer addAnimation:transition forKey:@"customTransitionPop"]; + + [self popViewControllerAnimated:NO]; +} + +@end