Gold challenge with xib


I found it very easy to add the cross-hairs with a xib. I made an image with the cross-hair, and then added it to an ImageView in a xib (CameraView.xib). Then I added the xib to DetailViewControler.m:

[code]- (IBAction)takePicture:(id)sender {
UIImagePickerController *imagePicker = [[UIImagePickerController alloc]init];
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
[imagePicker setSourceType:UIImagePickerControllerSourceTypeCamera];
//Load the xib into a UIView
UIView *crossh = [[[NSBundle mainBundle] loadNibNamed:@“CameraView” owner:self options:nil] objectAtIndex:0];
[imagePicker setCameraOverlayView:crossh];
} else {
[imagePicker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
[imagePicker setAllowsEditing:YES];
[imagePicker setDelegate:self];

[self presentViewController:imagePicker animated:YES completion:nil];


Just 2 lines of code. The only problem, as other people have noted, is that editing is not working, since the overlay is on top of the image. I tried checking/unchecking “User Interaction Enabled” for the Image View, but it makes no difference.

I guess I could do something like turn the Image View into a button (somehow), and when it’s clicked, have it disappear, or something like that, but seems overkill. Does anyone know of a way of disabling the overlay once you enter into the editing mode?


Try setting the view’s alpha (transparency) property to zero.

To cause a view to fade out/fade in on touches, you could do this:

@implementation MyView
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
    [UIView animateWithDuration:1.0 animations:^ {
        self.alpha = 0;

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
    [UIView animateWithDuration:1.0 animations:^ {
        self.alpha = 1;


Thanks for the reply, but where do I add the code? My view is a xib file, not a programmatic view. How does one have both?


That’s easy to do.

Set up an outlet connection to your view.

Or Subclass the view to create a custom view. Bring up the Identity Inspector in Interface Builder; go to the Custom Class section and change the Class attribute to your custom view.


I tried the code above, but it’s not working.

The view fades out, but I still can’t zoom, or move the picture.

I also tried setting it to hidden, but that didn’t work either.

Maybe I’m doing it wrong. I put the code above in the controller for the xib, not on a uiview.