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
19 changes: 19 additions & 0 deletions ChangingBackground.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -50,13 +52,17 @@
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>"; };
67B6165D1912C21100E08AC1 /* UINavigationController+CustomTransition.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UINavigationController+CustomTransition.h"; sourceTree = "<group>"; };
67B6165E1912C21100E08AC1 /* UINavigationController+CustomTransition.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UINavigationController+CustomTransition.m"; sourceTree = "<group>"; };
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 */
001809B2171C637E002D3E93 /* Frameworks */ = {
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 */,
Expand Down Expand Up @@ -86,6 +92,7 @@
001809B7171C637E002D3E93 /* Frameworks */ = {
isa = PBXGroup;
children = (
67B616621912C3D100E08AC1 /* QuartzCore.framework */,
001809B8171C637E002D3E93 /* UIKit.framework */,
001809BA171C637E002D3E93 /* Foundation.framework */,
001809BC171C637E002D3E93 /* CoreGraphics.framework */,
Expand All @@ -96,6 +103,7 @@
001809BE171C637E002D3E93 /* ChangingBackground */ = {
isa = PBXGroup;
children = (
67B6165C1912C1A100E08AC1 /* Categories */,
001809EF171C6768002D3E93 /* BackgroundImages */,
001809D5171C63FC002D3E93 /* AppDelegate */,
001809DC171C6453002D3E93 /* ViewControllers */,
Expand Down Expand Up @@ -167,6 +175,15 @@
name = BackgroundImages;
sourceTree = "<group>";
};
67B6165C1912C1A100E08AC1 /* Categories */ = {
isa = PBXGroup;
children = (
67B6165D1912C21100E08AC1 /* UINavigationController+CustomTransition.h */,
67B6165E1912C21100E08AC1 /* UINavigationController+CustomTransition.m */,
);
name = Categories;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -356,6 +374,7 @@
001809D4171C637E002D3E93 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
Expand Down
3 changes: 3 additions & 0 deletions ChangingBackground/AppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@

@interface AppDelegate : UIResponder <UIApplicationDelegate>

- (void)fadeFromBlueToGreenImage;
- (void)fadeFromGreenToBlueImage;

@end
45 changes: 45 additions & 0 deletions ChangingBackground/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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];

Expand All @@ -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
4 changes: 4 additions & 0 deletions ChangingBackground/ChangingBackground-Prefix.pch
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,8 @@
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import "AppDelegate.h"
#endif

//Adding a Macro to access the AppDelegate easily in other programs
#define APPDELEGATE ((AppDelegate*)[[UIApplication sharedApplication] delegate])
7 changes: 6 additions & 1 deletion ChangingBackground/FirstViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#import "FirstViewController.h"
#import "SecondViewController.h"
#import "UINavigationController+CustomTransition.h"

@interface FirstViewController ()

Expand All @@ -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
Loading