Skip to content

Commit

Permalink
add images on the fly
Browse files Browse the repository at this point in the history
  • Loading branch information
pulkitsinghal committed Mar 1, 2012
1 parent c6c9d14 commit edcfa02
Show file tree
Hide file tree
Showing 5 changed files with 523 additions and 12 deletions.
23 changes: 19 additions & 4 deletions screammachine.xcodeproj/project.pbxproj
Expand Up @@ -7,6 +7,7 @@
objects = { objects = {


/* Begin PBXBuildFile section */ /* Begin PBXBuildFile section */
A75849AD14FFA6650052299E /* UIImage+Utility.m in Sources */ = {isa = PBXBuildFile; fileRef = A75849AC14FFA6650052299E /* UIImage+Utility.m */; };
A7CB365614EB18CC00C50A61 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A7CB365514EB18CC00C50A61 /* UIKit.framework */; }; A7CB365614EB18CC00C50A61 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A7CB365514EB18CC00C50A61 /* UIKit.framework */; };
A7CB365814EB18CC00C50A61 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A7CB365714EB18CC00C50A61 /* Foundation.framework */; }; A7CB365814EB18CC00C50A61 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A7CB365714EB18CC00C50A61 /* Foundation.framework */; };
A7CB365A14EB18CC00C50A61 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A7CB365914EB18CC00C50A61 /* CoreGraphics.framework */; }; A7CB365A14EB18CC00C50A61 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A7CB365914EB18CC00C50A61 /* CoreGraphics.framework */; };
Expand All @@ -18,17 +19,19 @@
/* End PBXBuildFile section */ /* End PBXBuildFile section */


/* Begin PBXFileReference section */ /* Begin PBXFileReference section */
A75849AB14FFA6650052299E /* UIImage+Utility.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIImage+Utility.h"; sourceTree = "<group>"; };
A75849AC14FFA6650052299E /* UIImage+Utility.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIImage+Utility.m"; sourceTree = "<group>"; };
A7CB365114EB18CC00C50A61 /* screammachine.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = screammachine.app; sourceTree = BUILT_PRODUCTS_DIR; }; A7CB365114EB18CC00C50A61 /* screammachine.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = screammachine.app; sourceTree = BUILT_PRODUCTS_DIR; };
A7CB365514EB18CC00C50A61 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; }; A7CB365514EB18CC00C50A61 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
A7CB365714EB18CC00C50A61 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; A7CB365714EB18CC00C50A61 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
A7CB365914EB18CC00C50A61 /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; }; A7CB365914EB18CC00C50A61 /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; };
A7CB365D14EB18CC00C50A61 /* screammachine-Info.plist */ = {isa = PBXFileReference; path = "screammachine-Info.plist"; sourceTree = "<group>"; }; A7CB365D14EB18CC00C50A61 /* screammachine-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "screammachine-Info.plist"; sourceTree = "<group>"; };
A7CB365F14EB18CC00C50A61 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = "<group>"; }; A7CB365F14EB18CC00C50A61 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = "<group>"; };
A7CB366114EB18CC00C50A61 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; }; A7CB366114EB18CC00C50A61 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
A7CB366314EB18CC00C50A61 /* screammachine-Prefix.pch */ = {isa = PBXFileReference; path = "screammachine-Prefix.pch"; sourceTree = "<group>"; }; A7CB366314EB18CC00C50A61 /* screammachine-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "screammachine-Prefix.pch"; sourceTree = "<group>"; };
A7CB366414EB18CC00C50A61 /* AppDelegate.h */ = {isa = PBXFileReference; path = AppDelegate.h; sourceTree = "<group>"; }; A7CB366414EB18CC00C50A61 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
A7CB366514EB18CC00C50A61 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; }; A7CB366514EB18CC00C50A61 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
A7CB366714EB18CC00C50A61 /* ViewController.h */ = {isa = PBXFileReference; path = ViewController.h; sourceTree = "<group>"; }; A7CB366714EB18CC00C50A61 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = "<group>"; };
A7CB366814EB18CC00C50A61 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = "<group>"; }; A7CB366814EB18CC00C50A61 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = "<group>"; };
A7CB366B14EB18CC00C50A61 /* en */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = en; path = en.lproj/ViewController.xib; sourceTree = "<group>"; }; A7CB366B14EB18CC00C50A61 /* en */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = en; path = en.lproj/ViewController.xib; sourceTree = "<group>"; };
/* End PBXFileReference section */ /* End PBXFileReference section */
Expand All @@ -47,6 +50,15 @@
/* End PBXFrameworksBuildPhase section */ /* End PBXFrameworksBuildPhase section */


/* Begin PBXGroup section */ /* Begin PBXGroup section */
A75849AA14FFA65D0052299E /* utility */ = {
isa = PBXGroup;
children = (
A75849AB14FFA6650052299E /* UIImage+Utility.h */,
A75849AC14FFA6650052299E /* UIImage+Utility.m */,
);
path = utility;
sourceTree = "<group>";
};
A7CB364614EB18CC00C50A61 = { A7CB364614EB18CC00C50A61 = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
Expand Down Expand Up @@ -77,6 +89,7 @@
A7CB365B14EB18CC00C50A61 /* screammachine */ = { A7CB365B14EB18CC00C50A61 /* screammachine */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
A75849AA14FFA65D0052299E /* utility */,
A7CB366414EB18CC00C50A61 /* AppDelegate.h */, A7CB366414EB18CC00C50A61 /* AppDelegate.h */,
A7CB366514EB18CC00C50A61 /* AppDelegate.m */, A7CB366514EB18CC00C50A61 /* AppDelegate.m */,
A7CB366714EB18CC00C50A61 /* ViewController.h */, A7CB366714EB18CC00C50A61 /* ViewController.h */,
Expand Down Expand Up @@ -163,6 +176,7 @@
A7CB366214EB18CC00C50A61 /* main.m in Sources */, A7CB366214EB18CC00C50A61 /* main.m in Sources */,
A7CB366614EB18CC00C50A61 /* AppDelegate.m in Sources */, A7CB366614EB18CC00C50A61 /* AppDelegate.m in Sources */,
A7CB366914EB18CC00C50A61 /* ViewController.m in Sources */, A7CB366914EB18CC00C50A61 /* ViewController.m in Sources */,
A75849AD14FFA6650052299E /* UIImage+Utility.m in Sources */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };
Expand Down Expand Up @@ -274,6 +288,7 @@
A7CB367114EB18CC00C50A61 /* Release */, A7CB367114EB18CC00C50A61 /* Release */,
); );
defaultConfigurationIsVisible = 0; defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
}; };
/* End XCConfigurationList section */ /* End XCConfigurationList section */
}; };
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions screammachine/ViewController.h
Expand Up @@ -9,5 +9,13 @@
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>


@interface ViewController : UIViewController @interface ViewController : UIViewController
<UIImagePickerControllerDelegate, UINavigationControllerDelegate>

@property (nonatomic, retain) UIImagePickerController *imagePickerController;
@property (nonatomic, retain) UIButton *thisButtonNeedsPicture;

- (IBAction) showPopUp : (id) sender;

- (IBAction) takePicture : (id) sender;


@end @end
92 changes: 91 additions & 1 deletion screammachine/ViewController.m
Expand Up @@ -7,17 +7,107 @@
// //


#import "ViewController.h" #import "ViewController.h"
#import "UIImage+Utility.h"


@implementation ViewController @implementation ViewController


#pragma mark - Instance variables
@synthesize imagePickerController = _imagePickerController;
@synthesize thisButtonNeedsPicture = _thisButtonNeedsPicture;

#pragma mark - NSObject methods
- (id) initWithNibName : (NSString *) nibNameOrNil
bundle : (NSBundle *) nibBundleOrNil
{
if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]))
{
self.imagePickerController = [[UIImagePickerController alloc] init];
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
self.imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
}
self.imagePickerController.delegate = self;
}
return self;
}

- (void)didReceiveMemoryWarning - (void)didReceiveMemoryWarning
{ {
[super didReceiveMemoryWarning]; [super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use. // Release any cached data, images, etc that aren't in use.
} }


#pragma mark - View lifecycle #pragma mark - Instance methods
- (IBAction) showPopUp : (id) sender
{
UIAlertView *popUp =
[[UIAlertView alloc] initWithTitle : @"Guess Who?"
message : ((UIButton*)sender).titleLabel.text
delegate : nil
cancelButtonTitle : @"No Idea!"
otherButtonTitles : nil];
[popUp show];
}

- (IBAction) takePicture : (id) sender
{
if (((UIButton*)sender).imageView.image == nil) {
[self presentViewController:self.imagePickerController
animated:YES
completion:
^{
NSLog(@"This runs before the camera shutter opens :)");
self.thisButtonNeedsPicture = (UIButton*)sender;
}
];
} else {
[self showPopUp:sender];
}
}

#pragma mark - UIImagePickerControllerDelegate methods
- (void) imagePickerController : (UIImagePickerController *) picker
didFinishPickingImage : (UIImage *) image
{
NSLog(@"picked a picture");

//self.thisButtonNeedsPicture.imageView.image =
image =
[UIImage imageWithImage:image
scaledToSize:(CGSizeMake(85.0, 122.0))];

[self.thisButtonNeedsPicture setImage:image
forState:UIControlStateNormal];


[self dismissModalViewControllerAnimated:YES];
}

- (void) imagePickerController : (UIImagePickerController *) picker
didFinishPickingMediaWithInfo : (NSDictionary *) info
{
NSLog(@"took a picture");

NSLog(@"%@", self.thisButtonNeedsPicture);
NSLog(@"%@", self.thisButtonNeedsPicture.imageView);
NSLog(@"%@", self.thisButtonNeedsPicture.imageView.image);

//self.thisButtonNeedsPicture.imageView.image =
UIImage *image =
[UIImage imageWithImage:(UIImage *) [info objectForKey:UIImagePickerControllerOriginalImage]
scaledToSize:(CGSizeMake(85.0, 122.0))];

[self.thisButtonNeedsPicture setImage:image
forState:UIControlStateNormal];

[self dismissModalViewControllerAnimated:YES];
}

- (void)imagePickerControllerDidCancel : (UIImagePickerController *) picker
{
NSLog(@"did not take/pick a picture");
[self dismissModalViewControllerAnimated:YES];
}

#pragma mark - View lifecycle
- (void)viewDidLoad - (void)viewDidLoad
{ {
[super viewDidLoad]; [super viewDidLoad];
Expand Down

0 comments on commit edcfa02

Please sign in to comment.