Permalink
Browse files

Fix issues for iOS6, use standard image picker

Wanted the camera to show the picker option as part of the camera
screen. Also show the picker when no camera is detected.

This could probably be done by a parent controller, and maybe it should,
but I like this approach better.
  • Loading branch information...
1 parent d39800b commit 2510a1f48bff088baed0af9c6e28dd9b04b74f7d @sujal sujal committed Aug 23, 2012
@@ -17,7 +17,7 @@
- (void)imagePickerControllerDidCancel:(DLCImagePickerController *)picker;
@end
-@interface DLCImagePickerController : UIViewController {
+@interface DLCImagePickerController : UIViewController <UINavigationControllerDelegate,UIImagePickerControllerDelegate> {
GPUImageStillCamera *stillCamera;
GPUImageOutput<GPUImageInput> *filter;
GPUImageOutput<GPUImageInput> *blurFilter;
@@ -33,6 +33,7 @@
@property (nonatomic, weak) IBOutlet UIButton *cameraToggleButton;
@property (nonatomic, weak) IBOutlet UIButton *blurToggleButton;
@property (nonatomic, weak) IBOutlet UIButton *filtersToggleButton;
+@property (nonatomic, weak) IBOutlet UIButton *libraryToggleButton;
@property (nonatomic, weak) IBOutlet UIButton *flashToggleButton;
@property (nonatomic, weak) IBOutlet UIButton *retakeButton;
@@ -24,6 +24,7 @@ @implementation DLCImagePickerController {
cancelButton,
retakeButton,
filtersToggleButton,
+ libraryToggleButton,
filterScrollView,
filtersBackgroundImageView,
photoBar,
@@ -233,10 +234,8 @@ -(void) prepareLiveFilter {
-(void) prepareStaticFilter {
if (!staticPicture) {
- NSLog(@"Creating new static picture");
- [self.photoCaptureButton setTitle:@"Save" forState:UIControlStateNormal];
- UIImage *inputImage = [UIImage imageNamed:@"sample1.jpg"];
- staticPicture = [[GPUImagePicture alloc] initWithImage:inputImage smoothlyScaleOutput:YES];
+ // TODO: fix this hack
+ [self performSelector:@selector(switchToLibrary:) withObject:nil afterDelay:0.5];
}
[staticPicture addTarget:filter];
@@ -267,6 +266,14 @@ -(void) removeAllTargets {
[blurFilter removeAllTargets];
}
+-(IBAction)switchToLibrary:(id)sender {
+ UIImagePickerController* imagePickerController = [[UIImagePickerController alloc] init];
+ imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
+ // imagePickerController.mediaTypes = @[kUTTypeImage];
+ imagePickerController.delegate = self;
+ [self presentViewController:imagePickerController animated:YES completion:^(){}];
+}
+
-(IBAction)toggleFlash:(UIButton *)sender{
if([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera]
@@ -336,6 +343,7 @@ -(IBAction) takePhoto:(id)sender{
[stillCamera stopCameraCapture];
[self removeAllTargets];
[self.retakeButton setHidden:NO];
+ [self.libraryToggleButton setHidden:YES];
[self.cameraToggleButton setEnabled:NO];
[self.flashToggleButton setEnabled:NO];
staticPicture = [[GPUImagePicture alloc] initWithImage:processed smoothlyScaleOutput:YES];
@@ -369,6 +377,7 @@ -(IBAction) takePhoto:(id)sender{
-(IBAction) retakePhoto:(UIButton *)button{
[self.retakeButton setHidden:YES];
+ [self.libraryToggleButton setHidden:NO];
staticPicture = nil;
isStatic = NO;
[self removeAllTargets];
@@ -534,4 +543,30 @@ - (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
}
+#pragma mark - UIImagePickerDelegate
+
+- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
+ UIImage* outputImage = info[UIImagePickerControllerEditedImage];
+ if (outputImage == nil) {
+ outputImage = info[UIImagePickerControllerOriginalImage];
+ }
+
+ if (outputImage) {
+ staticPicture = [[GPUImagePicture alloc] initWithImage:outputImage smoothlyScaleOutput:YES];
+ isStatic = YES;
+ [self prepareStaticFilter];
+ }
+}
+
+- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
+ if (isStatic) {
+ // TODO: fix this hack
+ [self dismissModalViewControllerAnimated:NO];
+ [self.delegate imagePickerControllerDidCancel:self];
+ } else {
+ [self dismissModalViewControllerAnimated:YES];
+ [self retakePhoto:nil];
+ }
+}
+
@end
@@ -44,6 +44,7 @@ - (void)loadView
}
-(void) takePhoto:(id)sender{
+ NSLog(@"photo controller is %@", self);
DLCImagePickerController *picker = [[DLCImagePickerController alloc] init];
picker.delegate = self;
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:NO];
@@ -7,6 +7,8 @@
objects = {
/* Begin PBXBuildFile section */
+ 04338D0C15E6958B00BEAC52 /* library.png in Resources */ = {isa = PBXBuildFile; fileRef = 04338D0A15E6958A00BEAC52 /* library.png */; };
+ 04338D0D15E6958B00BEAC52 /* library@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 04338D0B15E6958B00BEAC52 /* library@2x.png */; };
6A42CF7615E46F0E0062D3E7 /* blur-on.png in Resources */ = {isa = PBXBuildFile; fileRef = 6A42CF7415E46F0E0062D3E7 /* blur-on.png */; };
6A42CF7715E46F0E0062D3E7 /* blur-on@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 6A42CF7515E46F0E0062D3E7 /* blur-on@2x.png */; };
6A49CEA715E345070098304F /* blackframe.png in Resources */ = {isa = PBXBuildFile; fileRef = 6A49CEA615E345070098304F /* blackframe.png */; };
@@ -111,6 +113,8 @@
/* End PBXContainerItemProxy section */
/* Begin PBXFileReference section */
+ 04338D0A15E6958A00BEAC52 /* library.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = library.png; sourceTree = "<group>"; };
+ 04338D0B15E6958B00BEAC52 /* library@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "library@2x.png"; sourceTree = "<group>"; };
6A42CF7415E46F0E0062D3E7 /* blur-on.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "blur-on.png"; sourceTree = "<group>"; };
6A42CF7515E46F0E0062D3E7 /* blur-on@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "blur-on@2x.png"; sourceTree = "<group>"; };
6A49CEA615E345070098304F /* blackframe.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = blackframe.png; sourceTree = "<group>"; };
@@ -347,6 +351,8 @@
6A5D9A9515E02527001FAD14 /* UI */ = {
isa = PBXGroup;
children = (
+ 04338D0A15E6958A00BEAC52 /* library.png */,
+ 04338D0B15E6958B00BEAC52 /* library@2x.png */,
6A42CF7415E46F0E0062D3E7 /* blur-on.png */,
6A42CF7515E46F0E0062D3E7 /* blur-on@2x.png */,
6A49CF0815E461D10098304F /* close.png */,
@@ -558,6 +564,8 @@
6A5530B615E486E300019CC9 /* 9@2x.jpg in Resources */,
6A5530B915E486E900019CC9 /* 10.jpg in Resources */,
6A5530BA15E486E900019CC9 /* 10@2x.jpg in Resources */,
+ 04338D0C15E6958B00BEAC52 /* library.png in Resources */,
+ 04338D0D15E6958B00BEAC52 /* library@2x.png in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -19,9 +19,10 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
- self.rootViewController = [[PhotoViewController alloc] initWithNibName:nil bundle:nil];
+ self.rootViewController = [[PhotoViewController alloc] init];
self.rootViewController.view.frame = [[UIScreen mainScreen] bounds];
[self.window addSubview:self.rootViewController.view];
+ self.window.rootViewController = self.rootViewController;
[self.window makeKeyAndVisible];
return YES;
}
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.

0 comments on commit 2510a1f

Please sign in to comment.