For my solution, it was easy enough to implement the pinch to zoom gesture. I was pleasantly surprised, as I have been doing iOS development using Flash Builder / AIR for my work and the application of pinch gesture is not difficult, it does not often work as I would like without significant effort.
Note, before I get flamed for using FB, my workplace is a non-Mac environment, so my options are limited .
Like others, I was concerned with not wanting to hard code the popover size, so I attempted to utilize Joes suggestion.
// according to docs UIPopoverController max for width is 600,
// height has no max
float w = 600;
if ( [[self image] size].width < w)
w = [[self image] size].width
h = [[self image] size].height;
[self setContentSizeForViewInPopover:CGSizeMake(w, h)];
CGSize sz = [[self image] size];
[imageView setFrame:CGRectMake(0, 0, sz.width, sz.height)];
[imageView setImage:[self image]];
(UIView *) viewForZoomingInScrollView:(UIScrollView *)scrollView
In ItemsViewController.m, I removed the call to setPopoverContentSize: from the showImage: atIndexPath: method.
- (void) showImage:(id)sender atIndexPath:(NSIndexPath *)ip
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
BNRItem *i = [[[BNRItemStore sharedStore] allItems] objectAtIndex:[ip row]];
NSString *imageKey = [i imageKey];
UIImage *img = [[BNRImageStore sharedStore] imageForKey];
CGRect rect = [[self view] convertRect:[sender bounds] fromView:sender];
ImageViewController *ivc = [[ImageViewController alloc] init];
imagePopover = [[UIPopoverController alloc] initWithContentViewController:ivc];
// [imagePopover setPopoverContentSize:CGSizeMake([ivc contentSizeForViewInPopover].width, [ivc contentSizeForViewInPopover].height) animated:YES];
This worked great to set the size of the popover so that it fit the contents but did not exceed the max value. However, when scaling the image down with pinch to zoom when the image size was smaller in width and / or height than the popover it always went to (0,0) coordinate. To fix this, I called the scrollViewDidZoom: method and did some checking to center the image when necessary.
Back in ImageViewController.m
(void) scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale
// get current image frame width and height
float currentWidth = [imageView frame].size.width;
float currentHeight = [imageView frame].size.height;
// find width and height for popover
float pw = [self contentSizeForViewInPopover].width;
float ph = [self contentSizeForViewInPopover].height;
float nx = 0.0;
float ny = 0.0;
if (currentWidth < pw)
nx = (pw - currentWidth) / 2;
if (currentHeight < ph)
ny = (ph - currentHeight) / 2;
// update the imageView frame if image width or height is smaller than the popover
if (nx != 0.0 || ny != 0.0)
[imageView setFrame:CGRectMake(nx, ny, currentWidth, currentHeight)];
I imagine this could have been done more elegantly, but it served my purposes.
Hope this can be of use and I am open to suggestions on cleaning this up where it makes sense.