Gold Challenge Solution


#1

As a note, this challenge only works with the camera so it has to be done on a device and not the simulator.

Updated one method within BNRDetailViewController.m

- (void)takePicture
{
    UIImagePickerController *imagePicker = [[UIImagePickerController alloc]init];
    
    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
    {
        imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
        
        UIImageView *crosshairs = [[UIImageView alloc]initWithFrame:[[UIScreen mainScreen]bounds]];
        crosshairs.image = [UIImage imageNamed:@"crosshairs.png"];
        crosshairs.alpha = 0.5f;
        crosshairs.contentMode = UIViewContentModeCenter;
        imagePicker.cameraOverlayView = crosshairs;
    }
    else
    {
        imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    }
    
    imagePicker.delegate = self;
    imagePicker.allowsEditing = YES;
    
    [self presentViewController:imagePicker animated:YES completion:nil];
}

#2

Nice solution. The apple solution available in the documentation was to create an a xib file with the image and then load that as an overlay. Yours seems simpler.

I noticed that the crosshairs are still there when you in editing mode of the photo. Any ideas of how to hide it then.


#3

[quote=“jeffkempster”]Nice solution. The apple solution available in the documentation was to create an a xib file with the image and then load that as an overlay. Yours seems simpler.

I noticed that the crosshairs are still there when you in editing mode of the photo. Any ideas of how to hide it then.[/quote]

This is a good question and one I just spent a lot of time with unsuccessfully. My thought was to register for a notification when a picture was taken and then remove the overlay. However, I can find no notification that messages when a picture is taken. I find it hard to believe that one does not exist but I am coming up empty. Once found the solution should be easy. The existing delegate only fires after a picture is selected so this is too late. There must be something in NSNotificationCenter so hopefully someone reads this and can chime in.


#4

stackoverflow.com/questions/1794 … ake-screen


#5

In my case, I created xib file with one image view with an image file specified. And then it was set to cameraOverlayView in takePicture.


@property (nonatomic, strong) IBOutlet UIView *overlayView;

- (IBAction)takePicture:(id)sender {
        ... ...
        imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;

        [[NSBundle mainBundle] loadNibNamed:@"OverlayView" owner:self options:nil];
        self.overlayView.frame = CGRectMake(self.view.center.x - 25,
                                            self.view.center.y - 25,
                                            50,
                                            50);
        imagePicker.cameraOverlayView = self.overlayView;