0

I would like to try and create a custom looking UIImagePickerController with its own controls I plan to make in an iPad view.

I have started by getting a UIView ready that I can load my picker into but it doesn't work; when I call the method it's in, nothing happens.

This is what my code looks like

UIView *cameraView = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 500, 300)];
[self.view addSubview:cameraView];

UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.showsCameraControls = NO;
picker.delegate = self;
[cameraView addSubview:picker.view];

[self presentViewController:picker animated:YES completion:NULL];
halfer
  • 19,824
  • 17
  • 99
  • 186
HurkNburkS
  • 5,492
  • 19
  • 100
  • 183
  • possible duplicate of [How to create a custom UIImagePickerController with full-screen images ios](http://stackoverflow.com/questions/15865368/how-to-create-a-custom-uiimagepickercontroller-with-full-screen-images-ios) – Adrian P Mar 22 '14 at 05:08
  • I dont want to take full screen images... thats why my camera view is smaller than full screen. I have been able to achive full screen using **[self presentViewController:picker animated:YES completion:NULL];** – HurkNburkS Mar 22 '14 at 05:20

1 Answers1

1

Let's try the below cameraOverlayView option to customize the camera screen,

Example :

-(void)takePhoto
{       
    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) 
    {
        cameraPickerController.sourceType = UIImagePickerControllerSourceTypeCamera;

             cameraPickerController.delegate = self;

         cameraPickerController.cameraOverlayView = [self getCameraToolBarWithAnimation:NO];

         cameraPickerController.showsCameraControls = NO;

             [self presentModalViewController:cameraPickerController animated:NO];

    }
    else
    {
        // Photo Library
    }

}

-(UIView *)getCameraToolBarWithAnimation:(BOOL)isAnimat
{
    UIView * fullView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)] autorelease];

    fullView.backgroundColor = [UIColor clearColor];

    if (isAnimat)
    {
        UIView * view = [[UIView alloc] initWithFrame:CGRectMake(0, 53.5, 320, 320)];

        view.backgroundColor = [UIColor whiteColor];

        [fullView addSubview:view];

        [self performSelector:@selector(shutterHide:) withObject:view afterDelay:0.25];

        [view release];
    }

    UIView * view = [[UIView alloc] initWithFrame:CGRectMake(0, 373.5, 320, 106.5)];

    view.backgroundColor = [UIColor blackColor];

    UIImageView * imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 53.5, 320, 53)];

    imageView.image = [UIImage imageNamed:@"capturetoolbar.png"];

    imageView.userInteractionEnabled = YES;

    CGPoint points[] = {CGPointMake(12, 55),CGPointMake(111, 100),CGPointMake(254, 55)};

    for (int i = 0; i < 3; i++)
    {
        UIButton * cameraButton = [UIButton buttonWithType:UIButtonTypeCustom];

        cameraButton.frame = CGRectMake(points[i].x, 7, points[i].y, 39);

        cameraButton.tag = i;

        [cameraButton addTarget:self action:@selector(cameraOptions:) forControlEvents:UIControlEventTouchUpInside];

        [imageView addSubview:cameraButton];
    }

    [view addSubview:imageView];

    UIView * topView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 53.5)];

    topView.backgroundColor = [UIColor blackColor];

    [fullView addSubview:topView];

    [fullView addSubview:view];

    [topView release];

    [view release];

    [imageView release];

    return fullView;
}

-(void)shutterHide:(UIView *)view
{
    [view retain];

    [UIView beginAnimations:nil context:view];

    [UIView setAnimationDuration:1.0];

    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];

    [UIView setAnimationDelegate:self];

    [view removeFromSuperview];

    [UIView commitAnimations];

    [view release];
} 

Thanks!

Natarajan
  • 3,241
  • 3
  • 17
  • 34