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
13 changes: 13 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 */; };
E4152A9B1831256600603A26 /* UIViewController+CBCategory.m in Sources */ = {isa = PBXBuildFile; fileRef = E4152A9A1831256600603A26 /* UIViewController+CBCategory.m */; };
E4AA9050182E68FC00525168 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E4AA904F182E68FC00525168 /* 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>"; };
E4152A991831256600603A26 /* UIViewController+CBCategory.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIViewController+CBCategory.h"; sourceTree = "<group>"; };
E4152A9A1831256600603A26 /* UIViewController+CBCategory.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIViewController+CBCategory.m"; sourceTree = "<group>"; };
E4AA904F182E68FC00525168 /* 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 = (
E4AA9050182E68FC00525168 /* QuartzCore.framework in Frameworks */,
001809B9171C637E002D3E93 /* UIKit.framework in Frameworks */,
001809BB171C637E002D3E93 /* Foundation.framework in Frameworks */,
001809BD171C637E002D3E93 /* CoreGraphics.framework in Frameworks */,
Expand All @@ -69,6 +75,8 @@
001809AC171C637E002D3E93 = {
isa = PBXGroup;
children = (
E4152A991831256600603A26 /* UIViewController+CBCategory.h */,
E4152A9A1831256600603A26 /* UIViewController+CBCategory.m */,
001809BE171C637E002D3E93 /* ChangingBackground */,
001809B7171C637E002D3E93 /* Frameworks */,
001809B6171C637E002D3E93 /* Products */,
Expand All @@ -86,6 +94,7 @@
001809B7171C637E002D3E93 /* Frameworks */ = {
isa = PBXGroup;
children = (
E4AA904F182E68FC00525168 /* QuartzCore.framework */,
001809B8171C637E002D3E93 /* UIKit.framework */,
001809BA171C637E002D3E93 /* Foundation.framework */,
001809BC171C637E002D3E93 /* CoreGraphics.framework */,
Expand Down Expand Up @@ -241,6 +250,7 @@
001809C5171C637E002D3E93 /* main.m in Sources */,
001809C9171C637E002D3E93 /* AppDelegate.m in Sources */,
001809D9171C6448002D3E93 /* FirstViewController.m in Sources */,
E4152A9B1831256600603A26 /* UIViewController+CBCategory.m in Sources */,
001809E0171C64E4002D3E93 /* SecondViewController.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -321,6 +331,7 @@
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "ChangingBackground/ChangingBackground-Prefix.pch";
INFOPLIST_FILE = "ChangingBackground/ChangingBackground-Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
PRODUCT_NAME = "$(TARGET_NAME)";
WRAPPER_EXTENSION = app;
};
Expand All @@ -332,6 +343,7 @@
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "ChangingBackground/ChangingBackground-Prefix.pch";
INFOPLIST_FILE = "ChangingBackground/ChangingBackground-Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
PRODUCT_NAME = "$(TARGET_NAME)";
WRAPPER_EXTENSION = app;
};
Expand All @@ -356,6 +368,7 @@
001809D4171C637E002D3E93 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
Expand Down
2 changes: 1 addition & 1 deletion ChangingBackground/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ @implementation AppDelegate
- (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];
Expand Down
1 change: 1 addition & 0 deletions ChangingBackground/FirstViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

#import <UIKit/UIKit.h>
#import "SecondViewController.h"

@interface FirstViewController : UIViewController

Expand Down
69 changes: 67 additions & 2 deletions ChangingBackground/FirstViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,79 @@
#import "SecondViewController.h"

@interface FirstViewController ()
@property (weak, nonatomic) IBOutlet UILabel *homeVCLabel;
@property (weak, nonatomic) IBOutlet UIButton *goForwardButton;

@end

@implementation FirstViewController
@synthesize goForwardButton;
@synthesize homeVCLabel;

CGRect labelRect;
CGRect buttonRect;
id observer;
UIImage *transitionImage;
UIImage *originalImage;


- (void)simulatePush {
[UIView animateWithDuration:0.2f animations:^{
goForwardButton.center = CGPointMake(buttonRect.origin.x - 300, buttonRect.origin.y);
homeVCLabel.center = CGPointMake(labelRect.origin.x - 300, labelRect.origin.y);
} completion:^(BOOL finished) {
SecondViewController *secondViewController = SecondViewController.new;
secondViewController.view.backgroundColor = [UIColor clearColor];
secondViewController.backgroundImage = originalImage;
[self.navigationController pushViewController:secondViewController animated:NO];
}];
}

- (void)preserveUIElementPositions {
// Additional UIElements would need to be added here
buttonRect = goForwardButton.frame;
labelRect = homeVCLabel.frame;
}

- (IBAction)goForwardButtonPressed {
SecondViewController *secondViewController = SecondViewController.new;
[self.navigationController pushViewController:secondViewController animated:YES];
[self simulatePush];
}

- (void)changeBackground {
for (UIView *subview in [self.view subviews]) {
if ([subview isKindOfClass:[UIImageView class]]) {
[subview removeFromSuperview];
}
}
UIImageView *oldImageView = [[UIImageView alloc] initWithImage:transitionImage];
UIImageView *newImageView = [[UIImageView alloc] initWithImage:originalImage];
[self.view insertSubview:oldImageView atIndex:0];
[UIView animateWithDuration:2.0f animations:^{
oldImageView.alpha = 0.0;
newImageView.alpha = 1.0;
[self.view insertSubview:newImageView atIndex:0];
}];
}

- (void)viewDidAppear:(BOOL)animated {
[UIView animateWithDuration:0.2f animations:^{
goForwardButton.frame = CGRectMake(buttonRect.origin.x, buttonRect.origin.y, buttonRect.size.width, buttonRect.size.height);
homeVCLabel.frame = CGRectMake(labelRect.origin.x, labelRect.origin.y, labelRect.size.width, labelRect.size.height);
}];
}

- (void)viewDidLoad {
[super viewDidLoad];
originalImage = [UIImage imageNamed:@"blue@2x.png"];
UIImageView *backgroundImageView = [[UIImageView alloc] initWithImage:originalImage];
[self.view insertSubview:backgroundImageView atIndex:0];
[self preserveUIElementPositions];

NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
observer = [nc addObserverForName:@"Go To VC1" object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *note) {
transitionImage = note.object;
[self changeBackground];
}];
}

@end
Loading