Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save onedayitwillmake/4156342 to your computer and use it in GitHub Desktop.
Save onedayitwillmake/4156342 to your computer and use it in GitHub Desktop.
Image Capture
//
// CameraMainViewController.h
// HSN
//
// Created by John Anderson on 11/26/12.
// Copyright (c) 2012 John Anderson. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface CameraMainViewController : UIViewController<UIImagePickerControllerDelegate,UINavigationControllerDelegate>{
}
@property (weak, nonatomic) IBOutlet UIView *cameraContainer;
#define CAMERA_TRANSFORM_X 1
#define CAMERA_TRANSFORM_Y 1.24299
// iPhone screen dimensions:
#define SCREEN_WIDTH 320
#define SCREEN_HEIGTH 548
@end
//
// CameraMainViewController.m
// HSN
//
// Created by John Anderson on 11/26/12.
// Copyright (c) 2012 John Anderson. All rights reserved.
//
#import "CameraMainViewController.h"
#import "Overlay.h"
#import "AddNewCardController.h"
@interface CameraMainViewController ()
@end
UIImagePickerController *picker;
Overlay *overlay;
UIButton *overlayButton;
@implementation CameraMainViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void) viewDidAppear:(BOOL)animated {
Overlay *overlay = [[Overlay alloc] initWithFrame:CGRectMake(0, 0, 320, 580)];
picker = [[UIImagePickerController alloc] init];
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){
[picker setSourceType:UIImagePickerControllerSourceTypeCamera];
picker.delegate = self;
picker.showsCameraControls = NO;
picker.navigationBarHidden = YES;
picker.wantsFullScreenLayout = YES;
picker.cameraViewTransform = CGAffineTransformScale(picker.cameraViewTransform, CAMERA_TRANSFORM_X, CAMERA_TRANSFORM_Y);
picker.cameraOverlayView = overlay;
overlayButton = [UIButton buttonWithType:UIButtonTypeCustom];
[overlayButton setFrame:CGRectMake(0, 0, 320, 455)];
[overlayButton addTarget:self action:@selector(scanButtonPressed) forControlEvents:UIControlEventTouchUpInside];
[picker.view addSubview:overlayButton];
}else{
[picker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
}
[self presentViewController:picker animated:YES completion:nil];
[super viewDidAppear:YES];
}
-(void)scanButtonPressed{
[self imagePickerControllerDidCancel:picker];
}
-(void)imagePickerControllerDidCancel:(UIImagePickerController *)imagePicker
{
[imagePicker dismissViewControllerAnimated:YES completion:^{
AddNewCardController *_add = [[AddNewCardController alloc] init];
_add.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentViewController:_add animated:YES completion:nil];
}];
}
@end
//
// ODViewController.m
// ODImagePickerTest
//
// Created by Mario Gonzalez on 11/27/12.
// Copyright (c) 2012 Mario Gonzalez. All rights reserved.
//
#import "ODViewController.h"
@interface ODViewController ()
@end
@implementation ODViewController
@synthesize picker=_picker;
@synthesize overlay=_overlay;
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
-(void)viewDidAppear:(BOOL)animated {
[super viewDidAppear: animated];
if(_picker) return;
ODOverlay *overlay = [[ODOverlay alloc] initWithFrame:CGRectMake(0, 0, 320, 580)];
_picker = [[UIImagePickerController alloc] init];
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){
[_picker setSourceType:UIImagePickerControllerSourceTypeCamera];
_picker.delegate = self;
_picker.showsCameraControls = NO;
_picker.navigationBarHidden = YES;
_picker.wantsFullScreenLayout = YES;
_picker.cameraViewTransform = CGAffineTransformScale(_picker.cameraViewTransform, CAMERA_TRANSFORM_X, CAMERA_TRANSFORM_Y);
_picker.cameraOverlayView = overlay;
_overlayButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_overlayButton setBackgroundColor:[UIColor colorWithRed:1.0 green:0.0 blue:0.0 alpha:0.25]];
[_overlayButton setFrame:CGRectMake(0, 0, 320, 455)];
[_overlayButton addTarget:self action:@selector(scanButtonPressed) forControlEvents:UIControlEventTouchUpInside];
[_picker.view addSubview:_overlayButton];
} else {
[_picker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
}
[self presentViewController:_picker animated:YES completion:nil];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 3 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
NSLog(@"Hello");
[_picker dismissViewControllerAnimated:YES completion:nil];
});
}
-(void)scanButtonPressed{
[self imagePickerControllerDidCancel: _picker];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
NSLog(@"didFinishPickingMediaWithInfo!");
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
NSLog(@"imagePickerControllerDidCancel!");
}
@end
//
// Overlay.h
// HSN
//
// Created by John Anderson on 11/26/12.
// Copyright (c) 2012 John Anderson. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface Overlay : UIView
@end
//
// Overlay.m
// HSN
//
// Created by John Anderson on 11/26/12.
// Copyright (c) 2012 John Anderson. All rights reserved.
//
#import "Overlay.h"
#import "AddNewCardController.h"
@implementation Overlay
- (id)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame]) {
// Clear the background of the overlay:
self.opaque = NO;
self.backgroundColor = [UIColor clearColor];
// Load the image to show in the overlay:
UIImage *overlayGraphic = [UIImage imageNamed:@"camera_card2.png"];
UIImageView *overlayGraphicView = [[UIImageView alloc] initWithImage:overlayGraphic];
overlayGraphicView.frame = CGRectMake(0, 0, 320, 580);
[self addSubview:overlayGraphicView];
}
return self;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment