Gold solution with editing


#1

Partial credit goes rkoftan for his crosshair code.

I originally tried putting rkoftan’s code into takePicture: but that resulted in not being able to edit the image. Instead you have to add the crosshair after the view controller has loaded which can be done through a UINavigationControllerDelegate method (navigationController:didShowViewController:animated:) since UIImagePickerViewController is a UINavigationController.

Add CoreGraphics.framework if you haven’t already in order to draw the crosshair.

DetailViewController.h (add BOOL for cameraMode)

@interface DetailViewController : UIViewController
<UINavigationControllerDelegate, UIImagePickerControllerDelegate, UITextFieldDelegate> {
    
    BOOL cameraMode;
    
}

DetailViewController.m

- (IBAction)takePicture:(id)sender {
    UIImagePickerController *imagePicker = [[UIImagePickerController alloc]init];
    
    if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
        [imagePicker setSourceType:UIImagePickerControllerSourceTypeCamera];
        cameraMode = YES;
    } else {
        [imagePicker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
    }
    imagePicker.allowsEditing = YES;
    [imagePicker setDelegate:self];
    
    [self presentViewController:imagePicker animated:YES completion:nil];
}
- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
    if(cameraMode) {
        int xCenter, yCenter;
        xCenter = (CGRectGetWidth(viewController.view.frame) /2);
        yCenter = (CGRectGetHeight(viewController.view.frame) /2);
        
        //draw horizonal line
        UIView *horLineView = [[UIView alloc] initWithFrame:CGRectMake(xCenter-25, yCenter, 50, 1)];
        horLineView.backgroundColor = [UIColor blackColor];
        [viewController.view addSubview:horLineView];
        
        //draw vertical line
        UIView *verLineView = [[UIView alloc] initWithFrame:CGRectMake(xCenter, yCenter-25, 1, 50)];
        verLineView.backgroundColor = [UIColor blackColor];
        [viewController.view addSubview:verLineView];
    }
}

#2

Ah, that’s one way to do it, by drawing it up :slight_smile: i just added an image. Nice work