PDA

View Full Version : How to customize UIImagePickerController




anuhoho
May 26, 2011, 04:48 AM
HI

I want to make an application which can customize the UIImagePickerCOntroller class.

Till now what I did is


//create an overlay view instance
PhotoLayoutView* overlay = [[PhotoLayoutView alloc]initWithFrame:CGRectMake(0, 0, 320, 480)];

// create the picker
UIImagePickerController* picker1 = [[UIImagePickerController alloc] init];
//[picker1 setAllowsEditing:YES];
[picker1 setSourceType:UIImagePickerControllerSourceTypeCamera];
[picker1 setDelegate:self];

//hide all controls
picker1.showsCameraControls = NO;
picker1.navigationBarHidden = YES;
picker1.toolbarHidden = YES;
//make the video preview full size
picker1.wantsFullScreenLayout = YES;
picker1.cameraViewTransform =
CGAffineTransformScale(picker1.cameraViewTransform,
1,
1.34299);
//set our custom overlay view
picker1.cameraOverlayView = overlay;
[self presentModalViewController:picker1 animated:YES];
[picker1 release];



PhotoLayout is another class for the overlay which has a button


- (id)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
//clear the background color of the overlay
self.opaque = NO;
self.backgroundColor = [UIColor clearColor];


//add a simple button to the overview with no functionality at the moment
ScanButton *scanButton = [[ScanButton alloc] initWithFrame:CGRectMake(10, 400, 157, 50)];

// Add a target action for the button:
[scanButton addTarget:self action:@selector(btnClicked) forControlEvents:UIControlEventTouchUpInside];

[self addSubview:scanButton];
}
return self;
}

- (void) btnClicked {

}


ScanButton class is where I put the image to the button


@implementation ScanButton

- (id)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
// Set button image:
UIImageView *buttonImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 157, 57)];
buttonImage.image = [UIImage imageNamed:@"capture.png"];

//[self addTarget:self action:@selector(buttonPressed) forControlEvents:UIControlEventTouchUpInside];

// TODO: Change opacity when being touched:

[self addSubview:buttonImage];

}
return self;
}




My first problem is the button is not showing in the view when i open the camera second is how can I call the takePicture method of UIImagePickerController with the btnClicked button in PhotoLayout class.