4

hi i have searched lot of for custom camera overlay view. i have find almost many sample projects but i can't still get perfect answer as i want to get. My question is i want to implement custom camera like instagram or picyou or other social networking apps on button click open custom camera using camera overlay view. i have created custom camera it works fine but i want to access the buttons actions like on capturing image it should navigate to other view by using UINavigationController but its not working.i have used this code for calling camera overlay view.

-(void)OpenCamera
{
    //create an overlay view instance
    OverlayView *overlay = [[OverlayView alloc]
                            initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGTH)];

    UIImagePickerController *picker = [[UIImagePickerController alloc] init]; 
    picker.delegate = self; 
    //        picker.allowsEditing = YES;
    picker.allowsEditing = NO;
    if (([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])) 
    {
        //set source to video!
        picker.sourceType = UIImagePickerControllerSourceTypeCamera;
        //hide all controls
        picker.showsCameraControls = NO;
        picker.navigationBarHidden = YES;
        picker.toolbarHidden = YES;
        //make the video preview full size
        picker.wantsFullScreenLayout = YES;
        picker.cameraViewTransform =
        CGAffineTransformScale(picker.cameraViewTransform,
                               CAMERA_TRANSFORM_X,
                               CAMERA_TRANSFORM_Y);
        //set our custom overlay view
        picker.cameraOverlayView = overlay;
//        picker.delegate = overlay;

//        UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:picker];

        //show picker
        [self presentModalViewController:picker animated:YES];  
    }
    else
    {
        picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
        picker.delegate = self;
        [self presentModalViewController:picker animated:YES];
    }
    [picker release];
}

and this is my camera overlay view .m file code i have used @interface OverlayView : UIView

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

    UIToolbar *toolbar = [UIToolbar new];

    toolbar.barStyle = UIBarStyleBlackTranslucent;

    // create a bordered style button with custom title

    UIBarButtonItem *Cancel = [[[UIBarButtonItem alloc] initWithTitle:@"Cancel"

                                                                  style:UIBarButtonItemStyleBordered    

                                                                 target:self

                                                                 action:@selector(btnCancel:)] autorelease];

    UIBarButtonItem *flexibleSpace1 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];

    UIBarButtonItem *Camera = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCamera target:self action:@selector(btnCapture:)] autorelease]; 

    UIBarButtonItem *flexibleSpace2 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];

    UIBarButtonItem *Album = [[[UIBarButtonItem alloc] initWithTitle:@"Gallery"

                                                                   style:UIBarButtonItemStyleBordered

                                                                  target:self

                                                                  action:@selector(btnLibrary:)] autorelease];

    NSArray *items = [NSArray arrayWithObjects: 

                      Cancel,
                      flexibleSpace1,
                      Camera,
                      flexibleSpace2,
                      Album,

                      nil];

    toolbar.items = items;

    // size up the toolbar and set its frame

    // please not that it will work only for views without Navigation toolbars. 

    [toolbar sizeToFit];

    CGFloat toolbarHeight = [toolbar frame].size.height;

    CGRect mainViewBounds = self.bounds;

    [toolbar setFrame:CGRectMake(CGRectGetMinX(mainViewBounds),

                                 CGRectGetMinY(mainViewBounds) + CGRectGetHeight(mainViewBounds) - (toolbarHeight),

                                 CGRectGetWidth(mainViewBounds),

                                 toolbarHeight)];

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

-(void)btnLibrary:(id)sender
{

}

-(void)btnCapture:(id)sender
{

}

-(void)btnCancel:(id)sender
{
//    [self dismissModalViewControllerAnimated:YES];
}

its all working fine but as i said i want to access buttons methods and the UINavigationController for changing the view like instagram and picyou its not working properly can you guide me how to navigate to another view.?

Hrushikesh Betai
  • 2,227
  • 5
  • 33
  • 63
  • 1
    thanx it is working fine but how can i remove the front rear button.i want to remove front rear button on the overlay view of camera – Jaspreet Singh Aug 29 '12 at 11:27

0 Answers0