diff --git a/ChangingBackground.xcodeproj/project.pbxproj b/ChangingBackground.xcodeproj/project.pbxproj index 2e16be1..96d76f5 100644 --- a/ChangingBackground.xcodeproj/project.pbxproj +++ b/ChangingBackground.xcodeproj/project.pbxproj @@ -24,6 +24,9 @@ 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 */; }; + D1A9332D191AD3FB00104BD3 /* BackgroundView.m in Sources */ = {isa = PBXBuildFile; fileRef = D1A9332C191AD3FB00104BD3 /* BackgroundView.m */; }; + D1A9332F191AF7E600104BD3 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D1A9332E191AF7E600104BD3 /* QuartzCore.framework */; }; + D1DD5F3E191C71B300340540 /* CustomButton.m in Sources */ = {isa = PBXBuildFile; fileRef = D1DD5F3D191C71B300340540 /* CustomButton.m */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -50,6 +53,11 @@ 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 = ""; }; + D1A9332B191AD3FB00104BD3 /* BackgroundView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BackgroundView.h; sourceTree = ""; }; + D1A9332C191AD3FB00104BD3 /* BackgroundView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BackgroundView.m; sourceTree = ""; }; + D1A9332E191AF7E600104BD3 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; }; + D1DD5F3C191C71B300340540 /* CustomButton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CustomButton.h; sourceTree = ""; }; + D1DD5F3D191C71B300340540 /* CustomButton.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CustomButton.m; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -57,6 +65,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + D1A9332F191AF7E600104BD3 /* QuartzCore.framework in Frameworks */, 001809B9171C637E002D3E93 /* UIKit.framework in Frameworks */, 001809BB171C637E002D3E93 /* Foundation.framework in Frameworks */, 001809BD171C637E002D3E93 /* CoreGraphics.framework in Frameworks */, @@ -86,6 +95,7 @@ 001809B7171C637E002D3E93 /* Frameworks */ = { isa = PBXGroup; children = ( + D1A9332E191AF7E600104BD3 /* QuartzCore.framework */, 001809B8171C637E002D3E93 /* UIKit.framework */, 001809BA171C637E002D3E93 /* Foundation.framework */, 001809BC171C637E002D3E93 /* CoreGraphics.framework */, @@ -96,6 +106,10 @@ 001809BE171C637E002D3E93 /* ChangingBackground */ = { isa = PBXGroup; children = ( + D1A9332B191AD3FB00104BD3 /* BackgroundView.h */, + D1A9332C191AD3FB00104BD3 /* BackgroundView.m */, + D1DD5F3C191C71B300340540 /* CustomButton.h */, + D1DD5F3D191C71B300340540 /* CustomButton.m */, 001809EF171C6768002D3E93 /* BackgroundImages */, 001809D5171C63FC002D3E93 /* AppDelegate */, 001809DC171C6453002D3E93 /* ViewControllers */, @@ -238,9 +252,11 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + D1DD5F3E191C71B300340540 /* CustomButton.m in Sources */, 001809C5171C637E002D3E93 /* main.m in Sources */, 001809C9171C637E002D3E93 /* AppDelegate.m in Sources */, 001809D9171C6448002D3E93 /* FirstViewController.m in Sources */, + D1A9332D191AD3FB00104BD3 /* BackgroundView.m in Sources */, 001809E0171C64E4002D3E93 /* SecondViewController.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -356,6 +372,7 @@ 001809D4171C637E002D3E93 /* Release */, ); defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; }; /* End XCConfigurationList section */ }; diff --git a/ChangingBackground/BackgroundView.h b/ChangingBackground/BackgroundView.h new file mode 100644 index 0000000..7915066 --- /dev/null +++ b/ChangingBackground/BackgroundView.h @@ -0,0 +1,18 @@ +// +// BackgroundImage.h +// ChangingBackground +// +// Created by Siddharth Sukumar on 5/7/14. +// Copyright (c) 2014 Ora Interactive. All rights reserved. +// + +#import + +@interface BackgroundView : UIView + +@property (nonatomic, strong) UIImage *backgroundImage; + +- (void) animatingTheForegroundImageWithImage : (UIImage *) image; + + +@end diff --git a/ChangingBackground/BackgroundView.m b/ChangingBackground/BackgroundView.m new file mode 100644 index 0000000..2efcabb --- /dev/null +++ b/ChangingBackground/BackgroundView.m @@ -0,0 +1,69 @@ +// +// BackgroundImage.m +// ChangingBackground +// +// Created by Siddharth Sukumar on 5/7/14. +// Copyright (c) 2014 Ora Interactive. All rights reserved. +// + +#import "BackgroundView.h" +#import + + +@interface BackgroundView () +@property (strong, nonatomic) UIImageView *imageView; + +@end + +@implementation BackgroundView + + +- (id)initWithCoder:(NSCoder *)aDecoder { + + self = [super initWithCoder:aDecoder]; + if (self){ + + NSArray *subViews = [self subviews]; + + id firstObject = subViews[0]; + + self.imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 320, 520)]; + + [self insertSubview:self.imageView belowSubview:firstObject]; + + } + return self; + +} + + +- (void) animatingTheForegroundImageWithImage : (UIImage *) image { + + self.imageView.image = image; + + CABasicAnimation *theAnimation; + + //within the animation we will adjust the "opacity"value of the layer + + theAnimation=[CABasicAnimation animationWithKeyPath:@"opacity"]; + theAnimation.duration=2; + + //changing the opacity (1=fully visible, 0=unvisible) + + theAnimation.fromValue=[NSNumber numberWithFloat:0.0]; + theAnimation.toValue=[NSNumber numberWithFloat:1.0]; + + [self.imageView.layer addAnimation:theAnimation + forKey:@"animateOpacity"]; + +} + +- (void) drawRect:(CGRect)rect { + + [super drawRect:rect]; + + [self.backgroundImage drawInRect:rect]; + +} + +@end diff --git a/ChangingBackground/CustomButton.h b/ChangingBackground/CustomButton.h new file mode 100644 index 0000000..28de33b --- /dev/null +++ b/ChangingBackground/CustomButton.h @@ -0,0 +1,18 @@ +// +// CustomButton.h +// ChangingBackground +// +// Created by Siddharth Sukumar on 5/8/14. +// Copyright (c) 2014 Ora Interactive. All rights reserved. +// + +#import + +@interface CustomButton : UIButton + + +- (void) indicatingItIsTheFirstViewControler; +- (void) indicatingItIsTheSecondViewController; + + +@end diff --git a/ChangingBackground/CustomButton.m b/ChangingBackground/CustomButton.m new file mode 100644 index 0000000..2b0e263 --- /dev/null +++ b/ChangingBackground/CustomButton.m @@ -0,0 +1,92 @@ +// +// CustomButton.m +// ChangingBackground +// +// Created by Siddharth Sukumar on 5/8/14. +// Copyright (c) 2014 Ora Interactive. All rights reserved. +// + +#import "CustomButton.h" + +@interface CustomButton() + +@property BOOL itIsTheFirstViewController; +@property BOOL itIsTheSecondViewController; + +@end + +@implementation CustomButton + +- (id)initWithFrame:(CGRect)frame +{ + self = [super initWithFrame:frame]; + if (self) { + // Initialization code + } + return self; +} + +- (void) setHighlighted:(BOOL)highlighted { + [super setHighlighted:highlighted]; + [self setNeedsDisplay]; + + +} + +- (void) indicatingItIsTheFirstViewControler { + + self.itIsTheFirstViewController = YES; + self.itIsTheSecondViewController = NO; + + +} +- (void) indicatingItIsTheSecondViewController { + + self.itIsTheSecondViewController = YES; + self.itIsTheFirstViewController = NO; + + +} + + + + +- (void) drawRect:(CGRect)rect { + + [super drawRect:rect]; + if (self.highlighted){ + + // Color Declarations + UIColor* color2 = [UIColor colorWithRed: 0 green: 0.629 blue: 1 alpha: 1]; + + // Rectangle Drawing + UIBezierPath* rectanglePath = [UIBezierPath bezierPathWithRect: rect]; + [color2 setFill]; + [rectanglePath fill]; + + + // Text Drawing + CGRect textRect = CGRectMake(64, 53, 102, 12); + { + NSString* textContent; + + if (self.itIsTheFirstViewController) { + textContent = @"Go Forward"; + + } else { + textContent = @"Go Back"; + + + } + NSMutableParagraphStyle* textStyle = NSMutableParagraphStyle.defaultParagraphStyle.mutableCopy; + textStyle.alignment = NSTextAlignmentCenter; + + NSDictionary* textFontAttributes = @{NSFontAttributeName: [UIFont fontWithName: @"Arial-BoldMT" size: UIFont.systemFontSize], NSForegroundColorAttributeName: UIColor.whiteColor, NSParagraphStyleAttributeName: textStyle}; + + [textContent drawInRect: CGRectOffset(textRect, 0, (CGRectGetHeight(textRect) - [textContent boundingRectWithSize: textRect.size options: NSStringDrawingUsesLineFragmentOrigin attributes: textFontAttributes context: nil].size.height) / 2) withAttributes: textFontAttributes]; + + } + + } +} +@end diff --git a/ChangingBackground/FirstViewController.m b/ChangingBackground/FirstViewController.m index 8aedb68..78d0f8b 100644 --- a/ChangingBackground/FirstViewController.m +++ b/ChangingBackground/FirstViewController.m @@ -8,16 +8,42 @@ #import "FirstViewController.h" #import "SecondViewController.h" +#import "BackgroundView.h" +#import "CustomButton.h" @interface FirstViewController () +@property (strong, nonatomic) IBOutlet BackgroundView *myView; +@property (strong, nonatomic) IBOutlet CustomButton *goForwardButton; @end @implementation FirstViewController +- (void)viewWillAppear:(BOOL)animated { + + [super viewWillAppear:YES]; + + self.myView.backgroundImage = [UIImage imageNamed:@"green"]; + + [self.goForwardButton indicatingItIsTheFirstViewControler]; + + // making the corners of the button round + + self.goForwardButton.layer.cornerRadius = 10.0; + self.goForwardButton.clipsToBounds = YES; + self.goForwardButton.showsTouchWhenHighlighted = YES; + [self.goForwardButton setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted]; + + [self.myView animatingTheForegroundImageWithImage:[UIImage imageNamed:@"blue"]]; + +} + + - (IBAction)goForwardButtonPressed { SecondViewController *secondViewController = SecondViewController.new; [self.navigationController pushViewController:secondViewController animated:YES]; + } @end + diff --git a/ChangingBackground/FirstViewController.xib b/ChangingBackground/FirstViewController.xib index 0dd58c2..e60a5d3 100644 --- a/ChangingBackground/FirstViewController.xib +++ b/ChangingBackground/FirstViewController.xib @@ -1,217 +1,45 @@ - - - - 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.m b/ChangingBackground/SecondViewController.m index 028f811..2d2d132 100644 --- a/ChangingBackground/SecondViewController.m +++ b/ChangingBackground/SecondViewController.m @@ -7,10 +7,43 @@ // #import "SecondViewController.h" +#import "BackgroundView.h" +#import +#import "CustomButton.h" + +@interface SecondViewController() + +@property (nonatomic, strong) IBOutlet BackgroundView *myView; +@property (strong, nonatomic) IBOutlet CustomButton *goBackButton; + + +@end @implementation SecondViewController +- (void)viewWillAppear:(BOOL)animated { + + [super viewWillAppear:YES]; + + self.myView.backgroundImage = [UIImage imageNamed:@"blue"]; + + [self.goBackButton indicatingItIsTheSecondViewController]; + + // making the corners of the button round + + self.goBackButton.layer.cornerRadius = 10.0; + self.goBackButton.clipsToBounds = YES; + [self.goBackButton setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted]; + self.goBackButton.showsTouchWhenHighlighted = YES; + + + // code for animating the foreground image + + [self.myView animatingTheForegroundImageWithImage:[UIImage imageNamed:@"green"]]; + +} + - (IBAction)goBackButtonPressed { [self.navigationController popViewControllerAnimated:YES]; } diff --git a/ChangingBackground/SecondViewController.xib b/ChangingBackground/SecondViewController.xib index d603949..6b077eb 100644 --- a/ChangingBackground/SecondViewController.xib +++ b/ChangingBackground/SecondViewController.xib @@ -1,243 +1,46 @@ - - - - 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