Gold Challenge Solution and question


For the Gold Challenge, i did this:

Created a new empty UIView like so.


@implementation CrossHairView

- (id)initWithFrame:(CGRect)frame
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        [self setBackgroundColor:[UIColor clearColor]];
    return self;

// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    CGRect bounds = [self bounds];
    //figure out the center of the bounds rectangle
    CGPoint center;
    center.x = bounds.origin.x + bounds.size.width / 2.0;
    center.y = bounds.origin.y + bounds.size.height / 2.0;
    //thickness of the line
    CGContextSetLineWidth(ctx, 1);
    //color of the line
    [[UIColor whiteColor] setStroke];
    int l = 20;
    CGContextMoveToPoint(ctx, 0, 0);
    CGContextAddLineToPoint(ctx, 0, bounds.size.height);
    CGContextAddLineToPoint(ctx, bounds.size.width, bounds.size.height);
     CGContextAddLineToPoint(ctx, bounds.size.width, 0);
     CGContextAddLineToPoint(ctx, 0,0);
    CGContextMoveToPoint(ctx, center.x, center.y);
    CGContextAddLineToPoint(ctx, center.x - l, center.y);
    CGContextAddLineToPoint(ctx, center.x + l, center.y);
    CGContextMoveToPoint(ctx, center.x, center.y);
    CGContextAddLineToPoint(ctx, center.x, center.y - l);
    CGContextAddLineToPoint(ctx, center.x, center.y + l);

then on DetailViewController.m


- (IBAction)takePicture:(id)sender
    UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
    [imagePicker setAllowsEditing:YES];
    //detect if the device has a camera
    if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
        // setCameraOverlayView: only works when sourceType is UIImagePickerControllerSourceTypeCamera 
        [imagePicker setSourceType:UIImagePickerControllerSourceTypeCamera];
        // make the rectangle bounds for the crosshair view
        // not sure why but the real height of the image preview doesn't start at 0,0 but at 0,1
        // also found no other way to get the right height of the image, thus the magic nuber 54
        CGRect overlayRect = CGRectMake(0, 1, [[imagePicker view] bounds].size.width, [[imagePicker view] bounds].size.height - 54);
        [imagePicker setCameraOverlayView:[[CrossHairView alloc] initWithFrame:overlayRect]];
        [imagePicker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
    [imagePicker setDelegate:self];
    [self presentViewController:imagePicker animated:YES completion:nil];


My question is if there is a way to get the actual height (or precise bounds of) of the photo preview programatically. There doesn’t seem to be any property in UIImagePickerController that will give this.

Any ideas?