Crosshairs Cameraoverlay not visible on ipad


#1

Hi
I can see the crosshairs overlay on the iphone but not in the popover on ipad. Am I missing something? I’ve tried adding the crosshairs view as a subview within the UIImagePickerController and a few other things but still no luck.

Here’s the takePicture method from DetailViewController.m and part of the crosshairs.m view where I’m using uses the pointInside: withEvent: to make the view non-responsive to touch events (thanks to @billyshih).

DetailViewController.m

[code]- (IBAction)takePicture:(id)sender {
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
Crosshairs *crosshairsView = [[Crosshairs alloc] initWithFrame:[self.view frame]];
// check whether the device has a camera
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
[imagePicker setSourceType:UIImagePickerControllerSourceTypeCamera];
[imagePicker setCameraOverlayView:crosshairsView];
}else {
[imagePicker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
}
[imagePicker setDelegate:self];
[imagePicker setAllowsEditing:YES];

// Check whether ipad or iphone
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
    imagePickerPopover = [[UIPopoverController alloc] initWithContentViewController:imagePicker];    
    [imagePickerPopover setDelegate:self];
    [imagePickerPopover presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; // present the popover from the sender button
} else {
    [self presentViewController:imagePicker animated:YES completion:nil];
}     

}[/code]

Crosshairs.m

[code]- (void)drawRect:(CGRect)rect
{

}

  • (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event
    {
    return NO;
    }[/code]

#2

To answer the question above, the problem was that the crosshairs view frame was being set with the wrong width and height

As far as I can tell, if you don’t set the popover controller dimensions beforehand, you can only get them using the popoverContentSize property. I can’t seem to get a frame size from an imagePicker controller view, e.g. cameraOverlayView, until that property is set/

[code]- (IBAction)takePicture:(id)sender {
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
[imagePicker setDelegate:self];
[imagePicker setAllowsEditing:YES];

Crosshairs *crosshairsView;

// check whether the device has a camera    
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {        
    [imagePicker setSourceType:UIImagePickerControllerSourceTypeCamera];
    crosshairsView = [[Crosshairs alloc] initWithFrame:self.view.frame];
    [imagePicker setCameraOverlayView:crosshairsView];
}else {
    [imagePicker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
}

// Check whether ipad or iphone
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
    imagePickerPopover = [[UIPopoverController alloc] initWithContentViewController:imagePicker];        
    CGSize popoverSize = [imagePickerPopover popoverContentSize]; // GET THE SIZE OF THE POPOVER
    CGRect crosshairsFrame = CGRectMake(0, 0, popoverSize.height, popoverSize.width); // CREATE A FRAME FOR THE CROSSHAIRS VIEW
    crosshairsView = [[Crosshairs alloc] initWithFrame:crosshairsFrame]; // CREATE THE CROSSHAIRS VIEW WITH THIS NEW FRAME
    [imagePicker setCameraOverlayView:crosshairsView];
    [imagePickerPopover setDelegate:self];
    [imagePickerPopover presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; // present the popover from the sender button        
} else {
    [self presentViewController:imagePicker animated:YES completion:nil];
}     

}[/code]

But, I get the feeling that these three lines:

CGSize popoverSize = [imagePickerPopover popoverContentSize]; // GET THE SIZE OF THE POPOVER CGRect crosshairsFrame = CGRectMake(0, 0, popoverSize.height, popoverSize.width); // CREATE A FRAME FOR THE CROSSHAIRS VIEW crosshairsView = [[Crosshairs alloc] initWithFrame:crosshairsFrame]; // CREATE THE CROSSHAIRS VIEW WITH THIS NEW FRAME

should be replaced by one, accessing something like imagePicker.cameraOverlayView.frame in the crosshairs view initialisation, which I don’t think exists at this point in the code. How does the cameraOverlayView get it frame size?
Anyone got any advice on this [, because I’m starting to obsess]?
Thanks, Steve


#3

After you present the popover, why not do something like this:

[crosshairsView setFrame:[[imagePicker view] bounds]];

#4

Great. Thanks. Needed to do some more reading on frame and bounds. Apple’s View Geometry page made the penny drop:

https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CocoaViewsGuide/Coordinates/Coordinates.html